1039. Find the Town Judge
My accepted C++ solution to LeetCode problem 1039, Find the Town Judge, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 65MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 65MB, accepted 2025-12-27.
class Solution {
public:
int findJudge(int n, vector<vector<int>>& trust) {
vector<int> score(n + 1, 0);
for (auto& t : trust) {
score[t[0]]--;
score[t[1]]++;
}
for (int i = 1; i <= n; i++) {
if (score[i] == n - 1) return i;
}
return -1;
}
};