Quick and Easy C++ Solution Beats 89% 2 Sets approach
Intuition\n Describe your first thoughts on how to solve this problem. \n- eliminate duplicates\n- find unique values in nums1 and nums 2 simultaneously\n# Appr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- eliminate duplicates\n- find unique values in nums1 and nums 2 simultaneously\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. We initialize 2 sets and store the values of the arrays in them to eliminate the duplicates.\n2. We run a for loop through the set containing nums1 and check if nums2 has the value using the set. If it doesn\'t, its unique to 1, so we add it to a vector. If it exists in both, we remove it from set 2 so that at the end, set 2 will have unique values to 2.\n3. After the for loop, set 2 should contain the values unique to 2 so we put them in a vector.\n4. Finally, we push both vectors into the vector of vectors to return.\n# Complexity\n- Time complexity: \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n+m), where n is the size of nums1 and m is the size of nums2.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n+m), where n is the size of nums1 and m is the size of nums2.\n\n![image.png](https://assets.leetcode.com/users/images/ef78b336-5c38-467b-8e2d-3f96a5e7fee6_1733037571.3389804.png)\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n        vector<vector<int>>res;\n        vector<int>uniqueOne;\n        unordered_set<int>n1(nums1.begin(), nums1.end());\n        unordered_set<int>n2(nums2.begin(), nums2.end());\n        for (auto x : n1){\n            if (n2.count(x) == 0){uniqueOne.push_back(x);}\n            else {n2.erase(x);}\n        }\n        res.push_back(uniqueOne);\n        vector<int>uniqueTwo(n2.begin(), n2.end());\n        res.push_back(uniqueTwo);\n        return res;\n    }\n};\n```
['C++']