-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode-349.cpp
More file actions
27 lines (24 loc) · 773 Bytes
/
LeetCode-349.cpp
File metadata and controls
27 lines (24 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*************************************************************************
> File Name: LeetCode-349.cpp
> Author: ltw
> Mail: 3245849061@qq.com
> Created Time: Sun 17 May 2020 12:34:02 PM CST
************************************************************************/
#include <iostream>
using namespace std;
class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
vector<int> ret;
unordered_map<int, int> s;
for (int i = 0; i < nums1.size(); i++) {
s[nums1[i]] = 1;
}
for (int i = 0; i < nums2.size(); i++) {
if (s[nums2[i]] == 0) continue;
ret.push_back(nums2[i]);
s[nums2[i]] -= 1;
}
return ret;
}
};