Single Number (Medium)

Description

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

Analysis

直接异或一下就好了

My Solution

1
2
3
4
5
6
7
8
9
10
11
//C++
class Solution {
public:
int singleNumber(int A[], int n) {
int ans = 0;
for(int i = 0;i<n;i++){
ans^=A[i];
}
return ans;
}
};