class Solution { public: int findJudge(int N, vector<vector<int>>& trust) { if (N==0) { return -1; } if (trust.empty()) { if (N == 1) { return 1; } else { return -1; } } unordered_map<int, int> be_trusted_num; unordered_map<int, int> trust_num; for (const auto p:trust) { auto b_itr = be_trusted_num.find(p[1]); if (b_itr == be_trusted_num.end()) { be_trusted_num[p[1]] = 1; } else { b_itr->second++; } auto t_itr = trust_num.find(p[0]); if (t_itr == trust_num.end()) { trust_num[p[0]] = 1; } else { t_itr->second++; } } for (const auto bt:be_trusted_num) { if (bt.second == N-1) { auto t_itr = trust_num.find(bt.first); if (t_itr == trust_num.end()) { return bt.first; } } } return -1; } };