Easy Solution C++ 🔥 Explained 🔥 Using Sets
PLEASE UPVOTE \uD83D\uDC4D\n# Intuition\n- ##### To solve this problem, we can create two sets: set1 and set2. We can then iterate through nums1 and add each in
# **PLEASE UPVOTE \uD83D\uDC4D**\n# Intuition\n- ##### To solve this problem, we can create two sets: set1 and set2. We can then iterate through nums1 and add each integer to set1. Similarly, we can iterate through nums2 and add each integer to set2.\n\n- ##### Next, we can take the set difference between set1 and set2 to obtain the distinct integers in nums1 that are not present in nums2. Similarly, we can take the set difference between set2 and set1 to obtain the distinct integers in nums2 that are not present in nums1.\n\n- ##### Finally, we can return the results in the form of a Vector of size 2, where the first element is the vector of distinct integers in nums1 that are not present in nums2, and the second element is the vector of distinct integers in nums2 that are not present in nums1.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Complexity\n- ### Time complexity: O(M+N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- ### Space complexity: O(M+N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# **PLEASE UPVOTE \uD83D\uDC4D**\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n        unordered_set<int> set1(nums1.begin(), nums1.end());\n        unordered_set<int> set2(nums2.begin(), nums2.end());\n        \n        vector<int> distinct_nums1, distinct_nums2;\n        for (int num : set1) {\n            if (set2.count(num) == 0) {\n                distinct_nums1.push_back(num);\n            }\n        }\n\n        for (int num : set2) {\n            if (set1.count(num) == 0) {\n                distinct_nums2.push_back(num);\n            }\n        }\n\n        return {distinct_nums1, distinct_nums2};\n    }\n};\n\n```\n![e2515d84-99cf-4499-80fb-fe458e1bbae2_1678932606.8004954.png](https://assets.leetcode.com/users/images/e5cc6438-63d7-47fb-84d1-e4e36cf43c6e_1683003574.1370602.png)\n
['Array', 'Ordered Set', 'C++']