Skip to content

Commit 72b8d84

Browse files
authored
Create 2092-find-all-people-with-secret.py
1 parent e8c19c0 commit 72b8d84

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def findAllPeople(self, n: int, meetings: List[List[int]], firstPerson: int) -> List[int]:
3+
secrets = set([0, firstPerson])
4+
time_map = {}
5+
6+
for src, dst, t in meetings:
7+
if t not in time_map:
8+
time_map[t] = defaultdict(list)
9+
time_map[t][src].append(dst)
10+
time_map[t][dst].append(src)
11+
12+
def dfs(src, adj):
13+
if src in visit:
14+
return
15+
visit.add(src)
16+
secrets.add(src)
17+
for nei in adj[src]:
18+
dfs(nei, adj)
19+
20+
for t in sorted(time_map.keys()):
21+
visit = set()
22+
for src in time_map[t]:
23+
if src in secrets:
24+
dfs(src, time_map[t])
25+
return list(secrets)

0 commit comments

Comments
 (0)