Skip to content

Instantly share code, notes, and snippets.

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