File tree 1 file changed +34
-0
lines changed
solution/0690. Employee Importance
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments