c++ code easy to understand hash map


  • 0
    G

    '''

    int missingNumber(vector<int>& nums) 
    {
        sort(nums.begin(),nums.end());
        map<int,int>temp;
        for(int i=0;i<nums.size()+1;++i)
        {
            ++temp[i];
        }
        for(int j=0;j<nums.size();++j)
        {
            --temp[nums[j]];
        }
        for(auto x:temp)
        {
            if(x.second!=0)
                return x.first;
        }
    }

Log in to reply
 

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