```
public class Solution {
public int[] singleNumber(int[] nums) {
int res[] = new int[2];
int xor = 0;
for (int i = 0; i < nums.length; i++) {
xor ^= nums[i];
}
int rightRes = xor & (~(xor - 1));
int group1 = 0, group2 = 0;
for (int i = 0; i < nums.length; i++) {
if ((rightRes & nums[i]) == 0) {
group1 ^= nums[i];
} else {
group2 ^= nums[i];
}
}
res[0] = group1;
res[1] = group2;
return res;
}
}
```