Skip to content

Commit 7ae0f84

Browse files
authored
Create remove-methods-from-project.py
1 parent f1386cf commit 7ae0f84

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Python/remove-methods-from-project.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Time: O(n + e)
2+
# Space: O(n + e)
3+
4+
# bfs
5+
class Solution(object):
6+
def remainingMethods(self, n, k, invocations):
7+
"""
8+
:type n: int
9+
:type k: int
10+
:type invocations: List[List[int]]
11+
:rtype: List[int]
12+
"""
13+
def bfs():
14+
lookup = [False]*n
15+
lookup[k] = True
16+
q = [k]
17+
while q:
18+
new_q = []
19+
for u in q:
20+
for v in adj[u]:
21+
if lookup[v]:
22+
continue
23+
lookup[v] = True
24+
new_q.append(v)
25+
q = new_q
26+
return lookup
27+
28+
adj = [[] for _ in xrange(n)]
29+
for u, v in invocations:
30+
adj[u].append(v)
31+
lookup = bfs()
32+
return [u for u in xrange(n) if not lookup[u]] if all(lookup[u] == lookup[v] for u, v in invocations) else range(n)

0 commit comments

Comments
 (0)