Created
May 5, 2021 12:27
-
-
Save vrat28/a9d0b1c48f808b28f05cf24a5b5de0d0 to your computer and use it in GitHub Desktop.
Jump Game
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
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