package leetcode;
public class Solution260 extends Solution {
@Override
public void test() {
int[] nums = {1, 2};
int[] ints = singleNumber(nums);
for (int anInt : ints) {
System.out.println(anInt);
}
}
public int[] singleNumber(int[] nums) {
if (nums.length < 2) return new int[]{};
if (nums.length < 3) {
return nums;
}
int pro = 0;
for(int i=0; i<nums.length; i++){
pro ^= nums[i];
}
int idx = 1;
while((pro & idx) == 0){
idx <<= 1;
}
int res1 = 0, res2 = 0;
for(int i=0; i<nums.length; i++){
if ((nums[i] & idx) != 0) {
res1 ^= nums[i];
}else{
res2 ^= nums[i];
}
}
return new int[]{res1, res2};
}
}