Skip to content

Commit a64ff97

Browse files
committed
Add Solution2.java to problems 0690
1 parent bffa1aa commit a64ff97

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
// Employee info
3+
class Employee {
4+
// It's the unique id of each node;
5+
// unique id of this employee
6+
public int id;
7+
// the importance value of this employee
8+
public int importance;
9+
// the id of direct subordinates
10+
public List<Integer> subordinates;
11+
};
12+
*/
13+
14+
import java.util.*;
15+
16+
class Solution {
17+
public int getImportance(List<Employee> employees, int id) {
18+
int ans = 0;
19+
for (Employee item : employees) {
20+
if (item.id == id) {
21+
if (item.subordinates.size() == 0) {
22+
return item.importance;
23+
}
24+
ans += item.importance;
25+
for (Employee e : item.subordinates) {
26+
ans += getImportance(employees, e.id);
27+
}
28+
return ans;
29+
}
30+
}
31+
return ans;
32+
}
33+
}

0 commit comments

Comments
 (0)