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/lzl124631x4// Time: O(A + B)5// Space: O(A + B)6class Solution {7public:8vector<vector<int>> findDifference(vector<int> &A, vector<int> &B) {9unordered_set<int> sa(begin(A), end(A)), sb(begin(B), end(B));10vector<vector<int>> ans(2);11for (int n : sa) {12if (sb.count(n) == 0) ans[0].push_back(n);13}14for (int n : sb) {15if (sa.count(n) == 0) ans[1].push_back(n);16}17return ans;18}19};