-
Notifications
You must be signed in to change notification settings - Fork 177
/
690.py
29 lines (29 loc) · 792 Bytes
/
690.py
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
"""
# Employee info
class Employee:
def __init__(self, id, importance, subordinates):
# It's the unique id of each node.
# unique id of this employee
self.id = id
# the importance value of this employee
self.importance = importance
# the id of direct subordinates
self.subordinates = subordinates
"""
class Solution:
def getImportance(self, employees, id):
"""
:type employees: Employee
:type id: int
:rtype: int
"""
def dfs(id):
self.val += dic[id].importance
for sub in dic[id].subordinates:
dfs(sub)
dic = {}
for emp in employees:
dic[emp.id] = emp
self.val = 0
dfs(id)
return self.val