Given an array of integers, every element appears twice except for one. Find that single one.
Could you implement it without using extra memory?
public int singleNumber(int[] A) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int res = 0;
for(int i =0;i<A.length;i++)
res ^= A[i];
return res;
}

本文介绍了一种不使用额外内存找出数组中仅出现一次的整数的方法。通过按位异或运算处理数组中的每个元素,最终得到那个唯一的整数。
3734

被折叠的 条评论
为什么被折叠?



