# LeetCode: 690. 员工的重要性¶

## 1、题目描述¶

输入: [[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1



1. 一个员工最多有一个**直系**领导，但是可以有多个**直系**下属
2. 员工数量不超过2000。

## 2、解题思路¶

​ 基本思路就是，建立一个哈希，或者说字典，保存id和里面内容的映射，不断的遍历属下，可以用递归，也可以使用list不断增加的特性，直到所有的都遍历完成

"""
# 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:
em = {}
def getImportance(self, employees, id):
"""
:type employees: Employee
:type id: int
:rtype: int
"""

for i in employees:
self.em[i.id] = i
# print(i)
return self.getSum(self.em[id])

def getSum(self,employee):
total = employee.importance
for i in employee.subordinates:
total += self.getSum(self.em[i])

"""
# 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
"""

em = {}
for i in employees:
em[i.id] = (i.importance, i.subordinates)

sub = em[id][1]
total = em[id][0];
for i in sub:
total += em[i][0]
sub += em[i][1]