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?
using namespace std;
class Solution {
public:
int singleNumber(vector<int>& A) {
int result=A[0];
for (int i=0;i<A.size();i++)
{
result=result^A[i];
}
return result;
}
};
int main(){
Solution s ;
vector<int> A={0,1,2,3,2,3,0};
int ss=s.singleNumber(A);
cout<< ss;
}
728

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



