-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1306.py
24 lines (20 loc) · 797 Bytes
/
1306.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
def canReach(self, arr: List[int], start: int) -> bool:
the_hash = [None] * len(arr)
while True:
changed = False
for i, v in enumerate(arr):
if the_hash[i] is not None:
continue
if i + arr[i] < len(arr) and (arr[i+arr[i]] == 0 or the_hash[i+arr[i]]):
the_hash[i] = True
changed = True
if start == i:
return True
if i - arr[i] >= 0 and (arr[i-arr[i]] == 0 or the_hash[i-arr[i]]):
the_hash[i] = True
changed = True
if start == i:
return True
if not changed:
return False