开始刷leetcode day31:Single Number

来源:互联网 发布:高斯如果在清华 知乎 编辑:程序博客网 时间:2024/06/03 11:51

Given an array of integers, every element appears twice except for one. Find that single one.

Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?



Java:

 public static int singleNumber(int[] A) {
int x = 0;
for (int a : A) {
x = x ^ a;
}
return x;
}

0 0