Preview:
class Solution {
public:
    int findJudge(int n, vector<vector<int>>& trust) {
        vector<int> v2(n+1,0);
        vector<int> v3(n+1,0);
        for(int i=0;i<trust.size();i++)
        {
            int u=trust[i][0];
            int v=trust[i][1];
            v2[v]++;
            v3[u]++;
        }
        int ans=-1;
       for(int i=1;i<=n;i++)
       {
           if(v2[i]==n-1&&v3[i]==0) ans=i;
       }
        return ans;
    }
};
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter