Skip to content

Commit 53b9ce9

Browse files
authored
Create find-the-town-judge.py
1 parent 67673e3 commit 53b9ce9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/find-the-town-judge.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Time: O(t + n)
2+
// Space: O(n)
3+
4+
class Solution {
5+
public:
6+
int findJudge(int N, vector<vector<int>>& trust) {
7+
vector<int> degrees(N);
8+
for (const auto& t : trust) {
9+
--degrees[t[0] - 1];
10+
++degrees[t[1] - 1];
11+
}
12+
for (int i = 0; i < degrees.size(); ++i) {
13+
if (degrees[i] == N - 1) {
14+
return i + 1;
15+
}
16+
}
17+
return -1;
18+
}
19+
};

0 commit comments

Comments
 (0)