forked from BigEggStudy/LeetCode-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0690-EmployeeImportance.cs
44 lines (39 loc) · 1.13 KB
/
0690-EmployeeImportance.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
33
34
35
36
37
38
39
40
41
42
43
44
//-----------------------------------------------------------------------------
// Runtime: 72ms
// Memory Usage: 20.8 MB
// Link: https://leetcode.com/submissions/detail/339601732/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
namespace LeetCode
{
/*
// Definition for Employee.
class Employee {
public int id;
public int importance;
public IList<int> subordinates;
}
*/
public class _0690_EmployeeImportance
{
public int GetImportance(IList<Employee> employees, int id)
{
var map = employees.ToDictionary(e => e.id, e => e);
return DFS(map, id);
}
private int DFS(IDictionary<int, Employee> map, int id)
{
var result = map[id].importance;
foreach (var subId in map[id].subordinates)
result += DFS(map, subId);
return result;
}
public class Employee
{
public int id;
public int importance;
public IList<int> subordinates;
}
}
}