-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee Importance
More file actions
36 lines (35 loc) · 1.04 KB
/
Employee Importance
File metadata and controls
36 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
# Definition for Employee.
class Employee(object):
def __init__(self, id, importance, subordinates):
#################
:type id: int
:type importance: int
:type subordinates: List[int]
#################
self.id = id
self.importance = importance
self.subordinates = subordinates
"""
class Solution(object):
def getImportance(self, employees, id):
"""
:type employees: List[Employee]
:type id: int
:rtype: int
"""
def dfs(id,importance):
visited.add(id)
importance[0] += graph[id][0]
for sub in graph[id][1]:
if sub not in visited:
dfs(sub,importance)
graph = defaultdict(list)
for employee in employees:
graph[employee.id].append(employee.importance)
graph[employee.id].append(employee.subordinates)
visited = set()
# print(graph)
importance=[0]
dfs(id,importance)
return importance[0]