Skip to content

Commit c162b15

Browse files
committed
997. Find the Town Judge
1 parent d4932a4 commit c162b15

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

find-the-town-judge.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Runtime: 196 ms
2+
// Memory Usage: 51.1 MB
3+
class Solution {
4+
public:
5+
int findJudge(int N, vector<vector<int>>& trust) {
6+
vector<int> inout(N + 1, 0);
7+
8+
for (auto t : trust) {
9+
inout[t[0]]--;
10+
inout[t[1]]++;
11+
}
12+
13+
for (int i = 1; i <= N; i++) {
14+
if (inout[i] == N - 1) {
15+
return i;
16+
}
17+
}
18+
return -1;
19+
20+
}
21+
};

0 commit comments

Comments
 (0)