-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path55.py
20 lines (20 loc) · 875 Bytes
/
55.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
__________________________________________________________________________________________________
sample 28 ms submission
class Solution:
def canJump(self, nums: List[int]) -> bool:
maxReach = 0
for i in range(len(nums)):
if (maxReach < i):
return False
maxReach = i+nums[i] if (i+nums[i] > maxReach) else maxReach
return True
__________________________________________________________________________________________________
sample 14044 kb submission
class Solution:
def canJump(self, nums: List[int]) -> bool:
last_good_po = len(nums)-1
for i in range(len(nums)-2, -1, -1):
if i + nums[i] >= last_good_po:
last_good_po = i
return last_good_po == 0
__________________________________________________________________________________________________