euisblue
997. Find the Town Judge

C++

1class Solution { 2 public: 3 int findJudge(int n, vector<vector<int>>& trust) { 4 vector<int> count(n+1, 0); 5 for(auto & t : trust) { 6 --count[t[0]]; // outbound 7 ++count[t[1]]; // inbound 8 } 9 10 for(int i=1; i<=n; ++i) { 11 if(count[i] == n-1) 12 return i; 13 } 14 15 return -1; 16 } 17};