-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlet690.py
32 lines (29 loc) · 895 Bytes
/
let690.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
30
31
32
# 690. Employee Importance
"""
# 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(employee, infos):
importance = employee.importance
for child in employee.subordinates:
importance += dfs(infos[child], infos)
return importance
infos = {}
for employee in employees:
infos[employee.id] = employee
return dfs(infos[id], infos)