Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created May 5, 2021 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/a9d0b1c48f808b28f05cf24a5b5de0d0 to your computer and use it in GitHub Desktop.
Save vrat28/a9d0b1c48f808b28f05cf24a5b5de0d0 to your computer and use it in GitHub Desktop.
Jump Game
class Solution {
public int jump(int[] nums) {
int jumps = 0, end = 0, maxFar = nums[0];
for ( int index = 0; index + 1 < nums.length; ++index ) {
maxFar = Math.max(index + nums[index], maxFar);
if ( index == end ) {
++jumps;
end = maxFar;
}
}
return jumps;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment