-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution690.cs
32 lines (28 loc) · 904 Bytes
/
Solution690.cs
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
31
32
namespace LeetCode.Solutions;
public class Solution690
{
/// <summary>
/// 690. Employee Importance - Medium
/// <a href="https://leetcode.com/problems/employee-importance">See the problem</a>
/// </summary>
public int GetImportance(IList<Employee> employees, int id)
{
var employeeMap = employees.ToDictionary(e => e.id);
return GetImportance(employeeMap, id);
}
private static int GetImportance(Dictionary<int, Employee> employeeMap, int id)
{
var employee = employeeMap[id];
var importance = employee.importance;
foreach (var subordinateId in employee.subordinates)
{
importance += GetImportance(employeeMap, subordinateId);
}
return importance;
}
public class Employee {
public int id;
public int importance;
public IList<int> subordinates;
}
}