We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5dd572e + 499baf9 commit 2bfe93aCopy full SHA for 2bfe93a
45.Jump Game II.cpp
@@ -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