[LeetCode]690. Employee Importance員工重要信息
阿新 • • 發佈:2018-01-24
blog nbsp shm new post employee sub helper pub
哈希表存id和員工數據結構
遞歸獲取信息
public int getImportance(List<Employee> employees, int id) { Map<Integer,Employee> map = new HashMap<>(); for (int i = 0; i < employees.size(); i++) { Employee temp = employees.get(i); map.put(temp.id,temp); }return helper(map,id); } public int helper(Map<Integer,Employee> map, int id) { Employee cur = map.get(id); List<Integer> sub = cur.subordinates; int res = cur.importance; for (int i = 0; i < sub.size(); i++) { res += helper(map,sub.get(i)); }return res; }
[LeetCode]690. Employee Importance員工重要信息