主要思路:异或 + 哈希
数组中只出现一次的数字
http://www.nowcoder.com/questionTerminal/e02fdb54d7524710a7d664d082bb7811
异或法则:
n^0 = n;
n^n = 0;
n^n^m = n^(n^m)
public void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) { if(array == null || array.length == 0)return; int res = 0; for(int i = 0;i < array.length;i++){ res ^=array[i]; } int index = res & (-res); num1[0] = 0;num2[0] = 0; for(int i = 0;i< array.length;i++){ if((index&array[i]) == 0){ num1[0] = num1[0] ^ array[i]; }else{ num2[0] = num2[0] ^array[i]; } } }