forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_690.java
28 lines (19 loc) · 765 Bytes
/
_690.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.fishercoder.solutions;
import com.fishercoder.common.classes.Employee;
import java.util.List;
import java.util.stream.Collectors;
public class _690 {
public static class Solution1 {
int total = 0;
public int getImportance(List<Employee> employees, int id) {
Employee manager = employees.stream().filter(e -> e.id == id).collect(Collectors.toList()).get(0);
total += manager.importance;
manager.subordinates.forEach(subId -> getImportance(employees, subId));
/**The above line is equivalent to below for loop*/
// for (int subId : manager.subordinates) {
// getImportance(employees, subId);
// }
return total;
}
}
}