Given an array of integers, all elements are repeated twice except for one. Find that single one.
Could you implement it without using extra memory?
牢记异或,愿异或母亲忽悠着你
class Solution { public: int singleNumber(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. if(n<1)return 0; int c=A[0]; for(int i=1;i<n;i++){ c^=A[i]; } return c; } };