Skip to content

Commit 2bfe93a

Browse files
authored
Merge pull request SjxSubham#147 from PralayeshMukherjee/main
45 Jump Game II.cpp
2 parents 5dd572e + 499baf9 commit 2bfe93a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

45.Jump Game II.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int jump(vector<int>& nums) {
4+
int right = 0, left = 0, steps = 0;
5+
while(right<nums.size()-1){
6+
int maxDist = 0;
7+
for(int i=left;i<=right;i++){
8+
maxDist = std::max(maxDist,nums[i]+i);
9+
}
10+
left = right+1;
11+
right = maxDist;
12+
steps++;
13+
}
14+
return steps;
15+
}
16+
};

0 commit comments

Comments
 (0)