Skip to content

Commit a6127c9

Browse files
committed
Jump Game 2
1 parent 6c79080 commit a6127c9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Arrays/JumpGameII.java

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

0 commit comments

Comments
 (0)