Posted on

Description

Submission

class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {
        map<int, int> m;
        for(int n : nums) {
            auto iter = m.find(n);
            if(iter == m.end()) m.insert(make_pair(n, 1));
            else m[n]++;
        }
        vector<int> res;
        for(auto iter = m.begin(); iter != m.end(); advance(iter, 1)) {
            if(iter->second == 1) res.push_back(iter->first);
        }
        return res;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *