LeetCode solutions

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

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 65MB, accepted 2025-12-27.

cpp
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;
    }
};

Source