My C++ solution using set and set_intersection


  • 0
    Y

    Runtime: 13 ms

    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
            set<int> s_nums1(nums1.begin(),nums1.end());
            set<int> s_nums2(nums2.begin(),nums2.end());
            vector<int> ans;
            set_intersection(s_nums1.begin(),s_nums1.end(),
                            s_nums2.begin(),s_nums2.end(),
                            back_inserter(ans));
            return ans;
    }
    

Log in to reply
 

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