Skip to content

Latest commit

 

History

History
18 lines (18 loc) · 455 Bytes

File metadata and controls

18 lines (18 loc) · 455 Bytes
class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        vector<int> res;
        int n = nums2.size();
        unordered_set<int> s(nums1.begin(), nums1.end());
        unordered_set<int> st;
        for (int &num : nums2) {
            if (s.count(num) && !st.count(num)) {
                res.push_back(num);
                st.insert(num);
            }
        }
        return res;
    }
};