Skip to content

Commit b7aaadb

Browse files
authored
Create minimum-number-of-vertices-to-reach-all-nodes.py
1 parent 8061b0e commit b7aaadb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(e)
2+
# Space: O(n)
3+
4+
class Solution(object):
5+
def findSmallestSetOfVertices(self, n, edges):
6+
"""
7+
:type n: int
8+
:type edges: List[List[int]]
9+
:rtype: List[int]
10+
"""
11+
result = []
12+
lookup = set()
13+
for u, v in edges:
14+
lookup.add(v)
15+
for i in xrange(n):
16+
if i not in lookup:
17+
result.append(i)
18+
return result

0 commit comments

Comments
 (0)