Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c5c49e7

Browse files
Added first solution to Hard category
1 parent 031efe4 commit c5c49e7

File tree

1 file changed

+22
-0
lines changed
  • LeetCodeSolutions/HardLevelSolutions/src/main/java/com/javaaid/solutions/hard/arrays

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
*
3+
*/
4+
package com.javaaid.solutions.hard.arrays;
5+
6+
/**
7+
* @author Kanahaiya Gupta
8+
*
9+
*/
10+
public class JumpGameII {
11+
public int jump(int[] nums) {
12+
int jumps = 0, ending_pos = 0, curr_pos = 0;
13+
for (int i = 0; i < nums.length-1; i++) {
14+
curr_pos = Math.max(curr_pos, i + nums[i]);
15+
if (i == ending_pos) {
16+
jumps++;
17+
ending_pos = curr_pos;
18+
}
19+
}
20+
return jumps;
21+
}
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /