Find the Town Judge LeetCode solution in Java
1class Solution {2public int findJudge(int n, int[][] trust) {3int count = 0;4int x[] = new int[n + 1];5int y[] = new int[n + 1];6Arrays.fill(x, 0);7Arrays.fill(y, 0);8for (int i = 0; i < trust.length; i++) {9x[trust[i][0]] = 1;10}11for (int i = 1; i <= n; i++) {12if (x[i] != 0) count++;13if (x[i] == 0) y[i] = 1;14}15if (count == n) return -1;16for (int i = 1; i <= n; i++) System.out.println(y[i]);17int jud = 0;18for (int i = 1; i <= n; i++) {19if (y[i] == 1) jud = i;20}21int c = 0;22for (int i = 0; i < trust.length; i++) {23if (trust[i][1] == jud) c++;24}25if (c == n - 1) return jud;26return -1;27}28}