We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bffa1aa commit a64ff97Copy full SHA for a64ff97
solution/0690. Employee Importance/Solution2.java
@@ -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
32
33
+}
0 commit comments