File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
solution/0690. Employee Importance Expand file tree Collapse file tree 1 file changed +33
-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
+ 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
+ }
You can’t perform that action at this time.
0 commit comments