Skip to content

Commit 5b5f754

Browse files
Sean PrashadSean Prashad
Sean Prashad
authored and
Sean Prashad
committed
Add 45_Jump_Game_II.java
1 parent d411f4f commit 5b5f754

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Arrays/45_Jump_Game_II.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int jump(int[] nums) {
3+
if (nums == null || nums.length == 0) {
4+
return 0;
5+
}
6+
7+
int result = 0, currEnd = 0, currFarthest = 0;
8+
9+
for (int i = 0; i < nums.length - 1; i++) {
10+
currFarthest = Math.max(currFarthest, i + nums[i]);
11+
12+
if (i == currEnd) {
13+
currEnd = currFarthest;
14+
++result;
15+
}
16+
}
17+
18+
return result;
19+
}
20+
}

0 commit comments

Comments
 (0)