找数组中重复的数字

一个数组中有一个重复的数字,空间复杂度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);
}
}

猜你喜欢

转载自www.cnblogs.com/zhaofeng555/p/11391056.html