Skip to content

Commit b483bb5

Browse files
authored
Update find-the-town-judge.py
1 parent d198d5e commit b483bb5

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

Python/find-the-town-judge.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
// Time: O(t + n)
2-
// Space: O(n)
1+
# Time: O(t + n)
2+
# Space: O(n)
33

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-
};
4+
class Solution(object):
5+
def findJudge(self, N, trust):
6+
"""
7+
:type N: int
8+
:type trust: List[List[int]]
9+
:rtype: int
10+
"""
11+
degrees = [0]*N
12+
for i, j in trust:
13+
degrees[i-1] -= 1
14+
degrees[j-1] += 1
15+
for i in xrange(len(degrees)):
16+
if degrees[i] == N-1:
17+
return i+1
18+
return -1

0 commit comments

Comments
 (0)