题目描述: 一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。
public static void FindNumsAppearOnce(int [] array
,int num1
[] , int num2
[]) {
Stack
<Integer> sta
= new Stack<>();
Arrays
.sort(array
);
for(int i
= 0; i
< array
.length
; i
++){
if(sta
.empty() || sta
.peek() != array
[i
]){
sta
.push(array
[i
]);
}else if(sta
.peek() == array
[i
]){
sta
.pop();
}
}
num1
[0] = sta
.pop();
num2
[0] = sta
.pop();
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-48989.html