Find the Difference of Two Arrays
IntuitionWe need to find unique elements in each of the two given lists. Using sets helps eliminate duplicates and allows efficient lookups.Approach
Convert num
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We need to find unique elements in each of the two given lists. Using sets helps eliminate duplicates and allows efficient lookups.
# Approach
<!-- Describe your approach to solving the problem. -->
1. Convert nums1 and nums2 into sets (set1 and set2) to remove duplicates.
2. Iterate through set1, adding elements not present in set2 to list1.
3. Iterate through set2, adding elements not present in set1 to list2.
4. Return {list1, list2}.
# Complexity
- Time complexity: O(nlogn+mlogm)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n+m)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
// class Solution {
// public:
//     vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {
//         vector<vector<int>> ans;
//         unordered_set<int> set1 (nums1.begin(), nums1.end());
//         unordered_set<int> set2 (nums2.begin(), nums2.end());

//         vector<int> list1, list2;
//         for(int num: set1){
//             if(set2.find(num) == set2.end()) list1.push_back(num);
//         }
//         for(int num: set2){
//             if(set1.find(num) == set1.end()) list2.push_back(num);
//         }
//     return {list1, list2};  
//     }
// };

class Solution {
public:
    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {
        set<int> set1 (nums1.begin(), nums1.end());
        set<int> set2 (nums2.begin(), nums2.end());

        vector<int> list1, list2;

        for(int num: set1){
            if(set2.find(num) == set2.end()) list1.push_back(num);
        }
        for(int num: set2){
            if(set1.find(num) == set1.end()) list2.push_back(num);
        }
        return {list1, list2};
    }
};
```
['Array', 'Hash Table', 'Ordered Set', 'C++']