# 0690. Employee Importance
###### tags: `Leetcode` `Medium` `Google` `DFS` `BFS`
Link: https://leetcode.com/problems/employee-importance/
## 思路 $O(N)$ $O(N)$
首先用map将employee id和employee连接起来,接下来正常dfs/bfs即可
由于题中规定One employee has at most one direct leader and may have several subordinates.所以不需要用set记录有没有visited过
## Code
```java=
class Solution {
public int getImportance(List<Employee> employees, int id) {
Map<Integer, Employee> map = new HashMap<>();
for(Employee employee:employees){
map.put(employee.id, employee);
}
return dfs(map, id);
}
private int dfs(Map<Integer, Employee> map, int id){
Employee curr = map.get(id);
int ans = 0;
ans += curr.importance;
for(int sub:curr.subordinates){
ans += dfs(map, sub);
}
return ans;
}
}
```