Skip to content

Commit 1061026

Browse files
committed
feat: jump-game
1 parent faf597f commit 1061026

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

jump-game/minji-go.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* <a href="https://leetcode.com/problems/jump-game/">week10-4. jump-game</a>
3+
* <li>Description: Return true if you can reach the last index, or false otherwise</li>
4+
* <li>Topics: Array, Dynamic Programming, Greedy </li>
5+
* <li>Time Complexity: O(N), Runtime 2ms </li>
6+
* <li>Space Complexity: O(1), Memory 45.66MB </li>
7+
*/
8+
class Solution {
9+
public boolean canJump(int[] nums) {
10+
int jump = 0;
11+
for (int i = 0; i <= jump; i++) {
12+
jump = Math.max(jump, i + nums[i]);
13+
if (jump >= nums.length - 1) {
14+
return true;
15+
}
16+
}
17+
return false;
18+
}
19+
}

0 commit comments

Comments
 (0)