We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a64ff97 commit 2d8fb24Copy full SHA for 2d8fb24
solution/0690. Employee Importance/Solution3.java
@@ -0,0 +1,34 @@
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
+ Map<Integer, Employee> map = new HashMap<>();
19
+ for (Employee employee : employees) {
20
+ map.put(employee.id, employee);
21
+ }
22
+ Stack<Employee> stack = new Stack<>();
23
+ stack.add(map.get(id));
24
+ int ant = 0;
25
+ while (!stack.isEmpty()) {
26
+ Employee pop = stack.pop();
27
+ ant += pop.importance;
28
+ for (Integer subordinate : pop.subordinates) {
29
+ stack.add(map.get(subordinate));
30
31
32
+ return ant;
33
34
+}
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments