Skip to content

Commit eb5e776

Browse files
committed
Add 997-FindTheTownJudge.cpp
1 parent 6138218 commit eb5e776

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int findJudge(int n, vector<vector<int>>& trust) {
4+
std::vector<long> from(n + 1, 0), to(n + 1, 0);
5+
for(long p = 0; p < trust.size(); p++){
6+
++from[trust[p][0]];
7+
++to[trust[p][1]];
8+
}
9+
10+
for(long p = 1; p <= n; p++){
11+
if(from[p] == 0 && to[p] == n - 1){return p;}
12+
}
13+
14+
return -1;
15+
}
16+
};

0 commit comments

Comments
 (0)