singlenumber

来源:互联网 发布:exe视频加密软件 编辑:程序博客网 时间:2024/05/16 11:14

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?

#include <iostream>
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;
}
原创粉丝点击