Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HarshKumarChoudary/f9150c84a1bf69d8bc6fbb8132743409 to your computer and use it in GitHub Desktop.
Save HarshKumarChoudary/f9150c84a1bf69d8bc6fbb8132743409 to your computer and use it in GitHub Desktop.
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