剑指offer-40
数组中只出现一次的数字
http://www.nowcoder.com/questionTerminal/e02fdb54d7524710a7d664d082bb7811
用容器记录出现过的数,出现第二次删除,最后留下两个,用set是因为它的查询时间比较快
import java.util.*; public class Solution { public void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) { Set<Integer> set = new HashSet<>(); for(Integer a : array){ if(set.contains(a)){ set.remove(a); }else { set.add(a); } } int i =0; for(Integer a : set){ if(i==0){ num1[0] = a; i=1; }else { num2[0] = a; } } } }