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

Method canJump

Array/JumpGame.py:37–61  ·  view source on GitHub ↗

:type nums: List[int] :rtype: bool

(self, nums)

Source from the content-addressed store, hash-verified

35"""
36class Solution(object):
37 def canJump(self, nums):
38 """
39 :type nums: List[int]
40 :rtype: bool
41 """
42
43
44 dp = [nums[0]]
45 current_index = 0
46
47 while 1:
48 if current_index + dp[-1] >= len(nums)-1:
49 return True
50 base = 0
51 index = current_index
52 for i in range(current_index, current_index+dp[-1]+1):
53 if nums[i] + i > base:
54 base = nums[i] + i
55 index = i
56
57 if current_index == index:
58 return False
59
60 current_index = index
61 dp.append(base-index)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected