public int[] singleNumber(int[] nums) {
        if (nums == null || nums.length == 0) return null;
        int xor = 0;
        for (int n : nums) xor ^= n;

        int i = 0;
        for(; i <= 31; ++i) {
            if ((xor >> i & 1) == 1) break;
        }

        int a = 0, b = 0;
        for (int n : nums) {
            if ((n >> i & 1) == 1) a ^= n;
            else b ^= n;
        }
        return new int[] {a, b};
    }