Skip to content

Commit 9492b15

Browse files
committed
feat: Solve jump-game problem
1 parent c9cdbfd commit 9492b15

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

jump-game/hu6r1s.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
# def canJump(self, nums: List[int]) -> bool:
3+
# if len(nums) == 1:
4+
# return True
5+
6+
# idx = 0
7+
# while idx < len(nums):
8+
# if idx == len(nums) - 1:
9+
# return True
10+
# if nums[idx] == 0:
11+
# return False
12+
13+
# idx += nums[idx]
14+
# return False
15+
16+
17+
def canJump(self, nums: List[int]) -> bool:
18+
maxReach = 0
19+
for i, num in enumerate(nums):
20+
if i > maxReach:
21+
return False
22+
maxReach = max(maxReach, i + num)
23+
return True
24+
"""
25+
while idx < len(nums)
26+
if nums[idx] == 0
27+
break
28+
idx += nums[idx]
29+
"""

0 commit comments

Comments
 (0)