Soln for intersection of vectors


  • 0
    R
    class Solution {
    public:
        vector<int> intersection(vector<int>& nums1, vector<int>& nums2) 
        {
            set<int> s;
            vector<int> v;
            for(int i=0;i<nums1.size();i++)
                for(int j=0;j<nums2.size();j++)
                {
                    if(nums1[i]==nums2[j])
                    {
                      s.insert(nums1[i]);
                    }
                }
            for(set<int>::iterator i=s.begin();i!=s.end();i++)
                v.push_back(*i);
            return v;
        }
    };
    

Log in to reply
 

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