In c++ a little slower though


  • 0
    A
    class Solution {
    public:
        int singleNumber(vector<int>& nums) {
            map<int, int> mymap;
            for(vector<int>::iterator it = nums.begin(); it != nums.end(); ++it){
                std::map<int,int>::iterator t;
                t = mymap.find(*it);
                if (t != mymap.end()){
                    mymap.erase(t);
                } else {
                    std::pair<std::map<int,int>::iterator,bool> ret;
                    ret = mymap.insert ( std::pair<int,int>(*it,1));
                }
            }
            std::map<int,int>::iterator t = mymap.begin();
            return t->first;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.