Can someone help to resolve the error with explanation


  • -3
    R

    class Solution {
    public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
    unordered_map<int,int> lookup;
    vector<int> result;
    for(auto x: nums1)
    lookup[x]++;
    for(auto n: nums2){
    if(--lookup[n]>=0){
    result.push_back(n);
    }

        }
       return result;        
    }
    

    };


  • 0
    G

    The numbers in result should be unique.


  • 0
    R

    how can i make it unique by this approach ??


Log in to reply
 

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