LeetCode 솔루션 분류
[5/18] 1557. Minimum Number of Vertices to Reach All Nodes
본문
태그
#Graph
관련자료
-
링크
댓글 2
JayShin님의 댓글
- 익명
- 작성일
# Time Complexity: O(n + e), Space Complexity: O(n)
class Solution:
def findSmallestSetOfVertices(self, n: int, edges: List[List[int]]) -> List[int]:
starts, ends = set(), set()
for f, t in edges:
starts.add(f)
ends.add(t)
return list(starts - ends)