We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d198d5e commit b483bb5Copy full SHA for b483bb5
Python/find-the-town-judge.py
@@ -1,19 +1,18 @@
1
-// Time: O(t + n)
2
-// Space: O(n)
+# Time: O(t + n)
+# 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
-};
+class Solution(object):
+ def findJudge(self, N, trust):
+ """
+ :type N: int
+ :type trust: List[List[int]]
+ :rtype: int
+ degrees = [0]*N
+ for i, j in trust:
+ degrees[i-1] -= 1
+ degrees[j-1] += 1
+ for i in xrange(len(degrees)):
+ if degrees[i] == N-1:
+ return i+1
+ return -1
0 commit comments