Skip to content

Commit 0f8f296

Browse files
committed
Runtime: 254 ms (Top 40.58%) | Memory: 15.6 MB (Top 60.31%)
1 parent 00910b6 commit 0f8f296

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Runtime: 254 ms (Top 40.58%) | Memory: 15.6 MB (Top 60.31%)
12
"""
23
# Definition for Employee.
34
class Employee:
@@ -11,27 +12,27 @@ class Solution:
1112
def dfs(self, graph, employees, empId, totalImportance, visited):
1213
totalImportance += graph[empId][0]
1314
visited.add(empId)
14-
15+
1516
for neighbour in graph[empId][1]:
1617
if neighbour not in visited:
1718
totalImportance = self.dfs(graph, employees, neighbour, totalImportance, visited)
18-
19+
1920
return totalImportance
20-
21+
2122
def getImportance(self, employees: List['Employee'], id: int) -> int:
2223
graph = {}
23-
24+
2425
for employeeInfo in employees:
2526
empId, importance, suboordinates = employeeInfo.id, employeeInfo.importance, employeeInfo.subordinates
2627
graph[empId] = [importance, suboordinates]
27-
28+
2829
n = len(employees)
29-
30+
3031
if graph[id][1] == []:
3132
return graph[id][0]
32-
33+
3334
visited = set()
3435
totalImportance = 0
3536
totalImportance = self.dfs(graph, employees, id, totalImportance, visited)
36-
37-
return totalImportance
37+
38+
return totalImportance

0 commit comments

Comments
 (0)