Find the Difference of Two Arrays LeetCode solution in C++

1
// OJ:
2
// https://leetcode.com/contest/weekly-contest-286/problems/find-the-difference-of-two-arrays/
3
// Author: github.com/lzl124631x
4
// Time: O(A + B)
5
// Space: O(A + B)
6
class Solution {
7
public:
8
vector<vector<int>> findDifference(vector<int> &A, vector<int> &B) {
9
unordered_set<int> sa(begin(A), end(A)), sb(begin(B), end(B));
10
vector<vector<int>> ans(2);
11
for (int n : sa) {
12
if (sb.count(n) == 0) ans[0].push_back(n);
13
}
14
for (int n : sb) {
15
if (sa.count(n) == 0) ans[1].push_back(n);
16
}
17
return ans;
18
}
19
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0