1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Solution { public int findChampion(int n, int[][] edges) { int[] inDegrees = new int[n]; for (int[] edge : edges) { inDegrees[edge[1]]++; }
int champion = -1; for (int i = 0; i < inDegrees.length; i++) { if (inDegrees[i] == 0) { if (champion == -1) { champion = i; } else { return -1; } } }
return champion; } }
|