Created
June 7, 2022 11:36
-
-
Save HarshKumarChoudary/f9150c84a1bf69d8bc6fbb8132743409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Solution::jump(vector<int> &a) { | |
int jmp = 0; | |
int cur = 0; | |
int next = 0; | |
for(int i = 0; i <= cur; ++ i){ | |
if(i == a.size()-1)return jmp; | |
next = max(next,a[i]+i); | |
if(i == cur){ | |
++jmp; | |
cur = next; | |
} | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment