C++ and JAVA both solutions using sets (9ms Beats 93.83% of Java sol | 32ms Beats 88.80% of C++ sol)
Intuition\nThe problem involves finding the differences between two arrays and returning the results in separate lists. My initial thoughts are to use sets to e
# Intuition\nThe problem involves finding the differences between two arrays and returning the results in separate lists. My initial thoughts are to use sets to efficiently identify unique elements in both arrays.\n\n# Approach\n1. **Set Initialization:**\n   - Create two sets, `s1` and `s2`, from the elements of `nums1` and `nums2`, respectively.\n\n2. **Find Differences:**\n   - For each element in `s1`, check if it is not present in `s2`. If true, add it to the first result list (`a1`).\n   - For each element in `s2`, check if it is not present in `s1`. If true, add it to the second result list (`a2`).\n\n3. **Return Result:**\n   - Return a vector (or list in Java) containing the two result lists (`a1` and `a2`).\n\n# Complexity\n- Time complexity:\n  - Constructing sets from the arrays has a time complexity of $$O(n)$$, where $$n$$ is the size of the arrays.\n  - Iterating through the sets and finding differences also has a time complexity of $$O(n)$$.\n\n- Space complexity:\n  - The space complexity is $$O(n)$$, where $$n$$ is the size of the sets. The sets store unique elements from the arrays. The result lists also contribute to the space complexity.\n\n# C++ Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2)\n    {\n        unordered_set<int> s1(nums1.begin(),nums1.end());\n        unordered_set<int> s2(nums2.begin(),nums2.end());\n        vector<int> a1,a2;\n        for(int it:s1)\n            if(!s2.contains(it))\n                a1.push_back(it);\n        for(int it:s2)\n            if(!s1.contains(it))\n                a2.push_back(it);\n        return {a1,a2};\n    }\n};\n```\n# Java Code\n```\npublic class Solution {\n    public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {\n        Set<Integer> set1 = new HashSet<>();\n        Set<Integer> set2 = new HashSet<>();\n        for (int num : nums1)\n            set1.add(num);\n        for (int num : nums2)\n            set2.add(num);\n        List<Integer> a1 = new ArrayList<>();\n        List<Integer> a2 = new ArrayList<>();\n        for (int num : set1) {\n            if (!set2.contains(num)) {\n                a1.add(num);\n            }\n        }\n        for (int num : set2) {\n            if (!set1.contains(num)) {\n                a2.add(num);\n            }\n        }\n        List<List<Integer>> result = new ArrayList<>();\n        result.add(a1);\n        result.add(a2);\n        return result;\n    }\n}\n```
['Array', 'Hash Table', 'C++', 'Java']