> For the complete documentation index, see [llms.txt](https://cai-sen-se.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cai-sen-se.gitbook.io/leetcode/601-800/690.-yuan-gong-de-zhong-yao-xing.md).

# 690. 员工的重要性

<https://leetcode-cn.com/problems/employee-importance/>

## 解法一：

以id为key，Employee结构为value写入map中，为了找出所有嵌套下属员工，用递归。

```python
"""
# 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
        """
        self.eMap = {}
        for e in employees:    #存入map
            self.eMap[e.id] = e
        return self.helper(id)
    
    def helper(self, id):
        imp = self.eMap[id].importance    #当前员工
        #递归访问下属员工
        for s in self.eMap[id].subordinates:
            imp += self.helper(s)
        return imp
```
