Use stl set for this question


  • 0
    B


    class Solution {
    public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
    set<int> st1(nums1.begin(), nums1.end());

        set<int> st;
        for (vector<int>::iterator itr = nums2.begin(); itr != nums2.end(); ++itr) {
            if (st1.find(*itr) != st1.end()) {
                st.insert(*itr);
            }
        }
        vector<int> vec(st.begin(), st.end());
        return vec;
    }
    

    };


Log in to reply
 

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