Участник:Mugadzhir/jump-game-iii

Материал из DISCOPAL
Перейти к: навигация, поиск
class Solution:
    def canReach(self, arr: List[int], start: int) -> bool:
        arr_len = len(arr)
        queue = [start]
        visited = set()
        while queue:
            subq = []
            for i in queue:
                if arr[i] == 0:
                    return True
                left = i - arr[i]
                right = i + arr[i]
                visited.add(i)
                if left  >= 0 and left not in visited:
                    subq.append(left)
                if right <= arr_len -1 and right not in visited:
                    subq.append(right)
            queue = subq
        return False