0
点赞
收藏
分享

微信扫一扫

LeetCode题解(1557):可以到达所有点的最少点数目(Python)


题目:​​原题链接​​(中等)

标签:图、有向图

解法

时间复杂度

空间复杂度

执行用时

Ans 1 (Python)

O ( E )

O ( N )

192ms (33%)

Ans 2 (Python)

Ans 3 (Python)

解法一:

class Solution:
def findSmallestSetOfVertices(self, n: int, edges: List[List[int]]) -> List[int]:
point = set([i for i in range(n)])

for edge in edges:
if edge[1] in point:
point.remove(edge[1])

return list(point)



举报

相关推荐

0 条评论