Jump Game (Leetcode 55)
Problem Link: https://leetcode.com/problems/jump-game/
class Solution:
def canJump(self, nums: List[int]) -> bool:
# Greedy Approach
n=len(nums)
goal=n-1
for i in range(n-1,-1,-1):
# Move the goal to front
# if it can be reached
if(nums[i]+i>=goal):
goal=i
if(goal==0):
return True
else:
return False
Last updated