1306. Jump Game III (Medium) - TengnanYao/daily_leetcode GitHub Wiki
class Solution(object):
def canReach(self, arr, start):
"""
:type arr: List[int]
:type start: int
:rtype: bool
"""
self.seen = set()
self.result = False
def dfs(arr, start):
if not self.result and start not in self.seen:
self.seen.add(start)
if arr[start] + start < len(arr):
if arr[arr[start] + start] == 0:
self.result = True
return
else:
dfs(arr, arr[start] + start)
if start - arr[start] >= 0:
if arr[start - arr[start]] == 0:
self.result = True
return
else:
dfs(arr, start - arr[start])
dfs(arr, start)
return self.result