Участник:S1td1kov/FindTheTownJudge

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/find-the-town-judge/

//follow my github https://github.com/RusS1103/Leetcode
const int ZERO = [](){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    return 0;
}();
 
class Solution {
public:
    int findJudge(int N, vector<vector<int>>& trust) {
        vector<vector<int>> counter(N, vector<int>(2,0));
        for(auto t : trust){
            counter[t[0]-1][1]++;
            counter[t[1]-1][0]++;
        }
        for(int i =0 ; i<N ; i++)if(counter[i][0] == N-1 && counter[i][1] == 0)return i+1;
        return -1;
    }
};