1557. Minimum Number of Vertices to Reach All Nodes

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1557

class Solution:
    def findSmallestSetOfVertices(self, n: int, edges: List[List[int]]) -> List[int]:
        cnt = Counter(t for _, t in edges)
        return [i for i in range(n) if cnt[i] == 0]