题目:
一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。
/num1,num2分别为长度为1的数组。传出参数
//将num1[0],num2[0]设置为返回结果
import java.util.HashMap;
public class Solution {
public void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) {
HashMap<Integer, Integer> hashMap = new HashMap<>();
int len = array.length;
for(int i=0;i<len;i++){
if(hashMap.containsKey(array[i])){
int num = hashMap.get(array[i]);
hashMap.put(array[i], ++num);
}else
hashMap.put(array[i], 1);
}
int j=1;
for(int i =0;i<len;i++){
if(hashMap.get(array[i])==1 &&j==1){
num1[0]= array[i];
j++;
}
if(hashMap.get(array[i])==1 &&j==2){
num2[0]= array[i];
}
}
}
}