C++ Solution with map


  • 0
    J
    class Solution {
    public:
        vector<int> findDisappearedNumbers(vector<int>& nums) {
            vector<int> result;
            map<int, int> hash;
            for(int num : nums)
                hash[num]++;
            for(int i = 1; i <= nums.size(); i++)
                if(hash[i] == 0)
                    result.push_back(i);
            return result;
        }
    };
    

Log in to reply
 

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