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?
public:
int singleNumber(int A[], int n) {
int i=0,result=A[0];
while(i++<n-1)
result=result^A[i];
return result;
}
};
本文介绍了一种使用异或操作解决寻找数组中唯一出现一次元素的方法。该算法具备线性时间复杂度,并且不需要额外内存,符合高效查找的要求。
412

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



