Posted on

Description

Submission

class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        unordered_set<int> Set;
        unordered_set<int> res;


        for(auto num: nums1) {
            if(Set.find(num) == Set.end()) {
                Set.insert(num);
            }
        }

        for(auto num: nums2) {
            if(Set.find(num) != Set.end() && res.find(num) == res.end()) {
                res.insert(num);
            }
        }

        return {res.begin(), res.end()};

    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *