【LeetCode】349. Intersection of Two Arrays

来源:互联网 发布:北大生命科学院知乎 编辑:程序博客网 时间:2024/06/03 13:57

题解:找相同元素不含重复值可以用set

vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {    set<int> st(nums1.begin(),nums1.end());    vector<int> res;    for(auto a:nums2)    {        if(st.erase(a)){            res.push_back(a);        }    }    return res;        }


原创粉丝点击