找数组中重复的数字

一个数组中有一个重复的数字,空间复杂度O(1),时间复杂度O(n)找出那个重复的数字。
public class QuChong {
public static void main(String[] args) {
int n = 4;
int[] arr = {1, 2, 3, 2};
int x = 0;
for (int i = 0; i <= n - 1; i++) {
x = x ^ i;
}
for (int i = 0; i < n; i++) {
x = x ^ arr[i];
}
System.out.println(x);
}
}
posted on 2019-08-21 20:33  zhaofeng555  阅读(160)  评论(0编辑  收藏  举报