Skip to content

Commit e23f7f4

Browse files
committed
- Jump Game DaleStudy#276
1 parent 7d75135 commit e23f7f4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

jump-game/ayosecu.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import List
2+
3+
class Solution:
4+
"""
5+
- Time Complexity: O(n), n = len(nums)
6+
- Space Complexity: O(1)
7+
"""
8+
def canJump(self, nums: List[int]) -> bool:
9+
max_jump = 0
10+
for i, jump in enumerate(nums):
11+
if i > max_jump:
12+
return False
13+
max_jump = max(max_jump, i + jump)
14+
return True
15+
16+
tc = [
17+
([2,3,1,1,4], True),
18+
([3,2,1,0,4], False)
19+
]
20+
21+
sol = Solution()
22+
for i, (n, e) in enumerate(tc, 1):
23+
r = sol.canJump(n)
24+
print(f"TC {i} is Passed!" if r == e else f"TC {i} is Failed! - Expected: {e}, Result: {r}")

0 commit comments

Comments
 (0)