Skip to content

Commit f085f7d

Browse files
committed
Adding solution to challenge '1376. Time Needed to Inform All Employees' (medium).
1 parent 1d115aa commit f085f7d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def numOfMinutes(self, n: int, headID: int, manager: List[int], informTime: List[int]) -> int:
3+
adjs = defaultdict(set)
4+
for i, parent in enumerate(manager):
5+
adjs[parent].add(i)
6+
ans = 0
7+
def dfs(cur, total):
8+
nonlocal ans
9+
if not adjs[cur]:
10+
ans = max(ans, total)
11+
for adj in adjs[cur]:
12+
dfs(adj, total+informTime[cur])
13+
dfs(headID, 0)
14+
return ans

0 commit comments

Comments
 (0)