https://leetcode.com/problems/jump-game/
time limit exceeded
even if using DP(memoization)..
why?
# 55. Jump Game (DP, medium)
class Solution:
def canJump(self, nums: List[int]) -> bool:
def jump(i, memo):
if i >= len(nums): return False
# reached at last index
if i == len(nums)-1: return True
if i in memo: return memo[i]
# enumerate all the possible choices
length = nums[i]
reachable = False
for j in range(1, length+1):
if jump(i+j, memo):
reachable = True
break
memo[i] = reachable
return reachable
return jump(0, {})