法官的入度为N-1,出度为0。
class Solution {
public int findJudge(int N, int[][] trust) {
int indegree[] = new int[N+1];
int outdegree[] = new int[N+1];
int result = -1;
for(int vector[] : trust){
int out = vector[0];
int in = vector[1];
indegree[in]++;
outdegree[out]++;
}
for(int i=1;i<=N;i++){
if(indegree[i] == N-1 && outdegree[i] == 0){
result = i;
}
}
return result;
}
}