-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
33 lines (31 loc) · 959 Bytes
/
solution.py
File metadata and controls
33 lines (31 loc) · 959 Bytes
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
"""
# Employee info
class Employee(object):
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(object):
def getImportance(self, employees, id):
"""
:type employees: Employee
:type id: int
:rtype: int
"""
importance = 0
stack = []
for employee in employees:
if employee.id == id:
stack.append(employee)
while len(stack) > 0:
employee = stack.pop()
importance += employee.importance
for e in employees:
if e.id in employee.subordinates:
stack.append(e)
return importance