Search

2024-04-21 Leetcode Daily Problem

생성일
2024/04/21 01:12
태그
알고리즘
날짜
2024/04/21
3 more properties
class Solution: def validPath(self, n: int, edges: List[List[int]], source: int, destination: int) -> bool: d = defaultdict(list) for x, y in edges: d[x].append(y) d[y].append(x) q, vis = {source}, set() while q: cur = q.pop() if cur == destination: return True if cur in vis: continue vis.add(cur) for adj in d[cur]: if adj in vis: continue q.add(adj) return False
Python
복사