c++ map


  • 0
    D

    class Solution {
    public:
    vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
    map<int,int> p;
    vector<int> q;
    int i,j;

        int len1=nums1.size();
        for(i=0;i<len1;i++)
            p[nums1[i]]++;
            
        int len2=nums2.size();
        for(i=0;i<len2;i++)
        {
            if(p[nums2[i]])
            {
                p[nums2[i]]--;
                q.push_back(nums2[i]);
            }
        }
        return q;
    }
    

    };


Log in to reply
 

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