
方法:设置标志位+计数
class Solution {
public List<List<Integer>> findWinners(int[][] matches) {
List<List<Integer>> ans = new ArrayList<>();
boolean[] flag = new boolean[100001];
int[] counter = new int[100001];
for (int[] m : matches) {
flag[m[0]] = true;
flag[m[1]] = true;
counter[m[1]]++;
}
List<Integer> zero = new ArrayList<>();
List<Integer> one = new ArrayList<>();
for (int i = 1; i <= 100000; i++) {
if (flag[i]) {
if (counter[i] == 0) {
zero.add(i);
} else if (counter[i] == 1) {
one.add(i);
}
}
}
ans.add(zero);
ans.add(one);
return ans;
}
}