Created
May 5, 2021 12:25
-
-
Save vrat28/88e3ff44fb284b467f171a5506d1adb8 to your computer and use it in GitHub Desktop.
Jump Game Python
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: | |
def jump(self, nums: List[int]) -> int: | |
n = len(nums) | |
steps = 0 | |
farthest = 0 | |
currentJumpEnd = 0 | |
for i in range(n-1): | |
farthest = max(farthest, i + nums[i]) | |
if i == currentJumpEnd: | |
steps += 1 | |
currentJumpEnd = farthest # Jump as far as possible | |
return steps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment