-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindJudge.cs
36 lines (29 loc) · 961 Bytes
/
FindJudge.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
//https://leetcode.com/problems/find-the-town-judge/description/
namespace LeetCode.Problems;
public sealed class FindJudge : ProblemBase
{
[Theory]
[ClassData(typeof(FindJudge))]
public override void Test(object[] data) => base.Test(data);
protected override void AddTestCases()
=> Add(it => it.Param(2).Param2dArray("[[1,2]]").Result(2))
.Add(it => it.Param(3).Param2dArray("[[1,3],[2,3]]").Result(3))
.Add(it => it.Param(3).Param2dArray("[[1,3],[2,3],[3,1]]").Result(-1));
private int Solution(int n, int[][] trust)
{
var map = new int[n, 2];
for (var i = 0; i < trust.Length; i++)
{
map[trust[i][1] - 1, 0] += 1;
map[trust[i][0] - 1, 1] = 1;
}
for (var i = 0; i < n; i++)
{
if (map[i, 0] == n - 1 && map[i, 1] == 0)
{
return i + 1;
}
}
return -1;
}
}