題目描述
一個(gè)整型數(shù)組里除了兩個(gè)數(shù)字之外,其他的數(shù)字都出現(xiàn)了兩次。請(qǐng)寫程序找出這兩個(gè)只出現(xiàn)一次的數(shù)字。
import java.util.HashSet;
import java.util.Set;
public class Solution {
public void FindNumsAppearOnce(int[] array, int num1[], int num2[]) {
Set<Integer> set = new HashSet<Integer>();
if(array == null || array.length == 0)
return;
for(int i = 0; i < array.length; i++) {
if(set.contains(array[i])){
set.remove(array[i]);
}else{
set.add(array[i]);
}
}
int[] num = new int[2];
int key = 0;
for(int i : set){
num[key ++] = i;
}
num1[0] = num[0];
num2[0] = num[1];
}
}