import java.util.Scanner;
//以下使用的是位运算的方法,不利用辅助空间
public class Main {
public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
int n ; // 表示总共有n个数, 重复一个数
int t = 0;
int a[] ;
n = sca.nextInt();
a = new int[n + 1];
//将数组中的数字添加到t中
for(int i = 0; i <= n; i ++) {
a[i] = sca.nextInt();
t = t ^ a[i];
}
//先将1--n的数字添加到t中异或进行去重
for(int i = 1; i <= n; i ++) {
t = t ^ i;
}
System.out.println(t);
}
}
如何找数组中唯一成对的那个数
猜你喜欢
转载自blog.csdn.net/qq_42794545/article/details/89319962
今日推荐
周排行