349. Intersection of Two Arrays

349. Intersection of Two Arrays
【思路】

  • 选择交叉元素;

利用set中元素的唯一性;

    set s(nums1.begin(), nums1.end());
    vector out;
    for (int x : nums2)
        if (s.erase(x))
            out.push_back(x);
    return out;

或者将两个排序,然后比较;

你可能感兴趣的:(349. Intersection of Two Arrays)