-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.java
30 lines (26 loc) · 796 Bytes
/
Main.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
29
30
package com.company;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
class Employee {
public int id;
public int importance;
public List<Integer> subordinates;
}
public class Main {
public static void main(String[] args) {
// write your code here
}
public int getImportance(List<Employee> employees, int id) {
Map<Integer, Employee> company = new HashMap<>();
for (Employee employee : employees)
company.put(employee.id, employee);
return dfs(company.get(id), company);
}
public int dfs(Employee employee, Map<Integer, Employee> company){
int res = employee.importance;
for (int id : employee.subordinates)
res += dfs(company.get(id), company);
return res;
}
}