0
点赞
收藏
分享

微信扫一扫

【Leetcode_easy】690. Employee Importance

软件共享软件 2022-07-12 阅读 92

problem

​​690. Employee Importance​​

题意:所有下属和自己的重要度之和,所有下属包括下属的下属即直接下属和间接下属。

solution:DFS;

/*
// Employee info
class Employee {
public:
// It's the unique ID of each node.
// unique id of this employee
int id;
// the importance value of this employee
int importance;
// the id of direct subordinates
vector<int> subordinates;
};
*/
class Solution {
public:
int getImportance(vector<Employee*> employees, int id) {
unordered_map<int, Employee*> mymap;//err.
for(auto employee:employees) mymap[employee->id] = employee;
return helper(id, mymap);
}
int helper(int id, unordered_map<int, Employee*> m) {
int res = m[id]->importance;
for(auto num:m[id]->subordinates)//err.
{
res += helper(num, m);
}
return res;
}
};

 solution:BFS;

 

 

 

参考

1. ​​Leetcode_easy_690. Employee Importance​​;

2. ​​Grandyang​​;

完 

 

举报

相关推荐

0 条评论