We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7d75135 commit e23f7f4Copy full SHA for e23f7f4
jump-game/ayosecu.py
@@ -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