【Leetcode_easy】690. Employee Importance
problem
题意:所有下属和自己的重要度之和,所有下属包括下属的下属即直接下属和间接下属。
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;
参考
2. Grandyang;
完
各美其美,美美与共,不和他人作比较,不对他人有期待,不批判他人,不钻牛角尖。
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
浙公网安备 33010602011771号