class Solution {
public int[] singleNumbers(int[] nums) {
if (nums == null) {
return new int[0];
}
Set<Integer> set = new HashSet<>(2);
for (int i = 0; i < nums.length; i++) {
if (set.contains(nums[i])) {
set.remove(nums[i]);
} else {
set.add(nums[i]);
}
}
return set.stream().mapToInt(i -> i).toArray();
}
}
评论