题目描述:
方法一:分组异或
class Solution { public int[] singleNumbers(int[] nums) { int sum = 0; int [] res = new int[2]; for(int num:nums){ sum ^= num; } int lowbit = sum & (-sum); for(int num:nums){ if((num & lowbit) == 0){ res[0] ^= num; }else{ res[1] ^= num; } } return res; } }
附:找出一个数二进制送第一位不是0的:h=num^(num&(num-1))