MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

Array/JumpGameII.py:28–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27"""
28class Solution(object):
29 def jump(self, nums):
30 """
31 :type nums: List[int]
32 :rtype: int
33 """
34 if len(nums) == 1:
35 return 0
36
37 # dp = [nums[0]]
38 maxes = nums[0]
39 count = 1
40 current_index = 0
41 length = len(nums) - 1
42 while 1:
43 if current_index + maxes >= length:
44 return count
45 base = 0
46 index = current_index
47 for i in xrange(current_index, current_index+maxes+1):
48 if nums[i] + i > base:
49 base = nums[i] + i
50 index = i
51
52 current_index = index
53 maxes = base-index
54 count += 1

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected