c++ with set solution


  • 0
    F
    vector<int> Intersection_of_Two_Arrays::intersection(vector<int> &nums1, vector<int> &nums2) {
        set<int> unique_slice(nums1.begin(), nums1.end());
        vector<int> result;
        for (auto i : nums2) {
            if (unique_slice.erase(i)){
                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.