Simple way using multiset to solve it


  • -3
    P
    int singleNumber(vector<int>& nums) 
    {
        multiset<int> s(nums.begin(),nums.end());
        multiset<int>::iterator i;
        for(i = s.begin();i!=s.end();i++)
        {
            if(s.count(*i)!=3)
            {
                return *i;
                break;
            }
        }
    }

Log in to reply
 

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