Skip to content

Commit edf43b2

Browse files
authored
Create jump-game-ii.cpp
1 parent dc83413 commit edf43b2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

jump-game-ii.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
int jump(vector<int>& nums) {
4+
int j = 0, curr = 0, maxReach = 0;
5+
for(int i = 0 ; i < nums.size()-1; i++){
6+
maxReach = max(maxReach,i+nums[i]);
7+
if(i == curr) {
8+
j++;
9+
curr = maxReach;
10+
}
11+
}
12+
return j;
13+
}
14+
};

0 commit comments

Comments
 (0)