通过一个辅助数组去计数
把aa[x]中的值作为help中的下标,对help中对应下标的值进行增加
遍历help 哪一个为2 则他的下标就是成对的值
public class Demo1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
//找出唯一成对数
int[] aa = new int[4];
aa[0] = 0;
aa[1] = 1;
aa[2] = 2;
aa[3] = 1;
int[] help = new int[4];
//通过一个辅助数组去计数
//把aa[x]中的值作为help中的下标,对help中对应下标的值进行增加
//遍历help 哪一个为2 则他的下标就是成对的值
for (int i = 0; i < aa.length; i++) {
help[aa[i]]++;
}
for (int i = 0; i < help.length; i++) {
if (help[i] == 2) {
System.out.println(i);
}
}
}
}