2215 | c++ | Easy O(nlogn) solution | 2 approaches
Approach-1: Use sets to find difference\n\nTC: O(nlogn), SC: O(1)\n\nCode:\n\nclass Solution {\npublic:\n    vector<vector<int>> findDifference(vector<int>& num
**Approach-1:** Use sets to find difference\n\n**TC: O(nlogn), SC: O(1)**\n\n**Code:**\n```\nclass Solution {\npublic:\n    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n        \n        set<int> s1, s2;\n        \n        for(auto it:nums1)\n            s1.insert(it);\n        \n        for(auto it:nums2)\n            s2.insert(it);\n        \n        vector<vector<int>> ans(2);\n        \n        for(auto it : s1)\n        {\n            if(s2.count(it) == 0)\n                ans[0].push_back(it);\n        }\n        \n        for(auto it : s2)\n        {\n            if(s1.count(it) == 0)\n                ans[1].push_back(it);\n        }\n        \n        return ans;\n    }\n};\n```\n\n**Approach-1:** Use find operation to get the difference of two arrays\n\n**TC: O(n^2), SC: O(1)**\n\n**Code:**\n```\nclass Solution {\npublic:\n    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n        \n        vector<vector<int>> ans(2);\n        \n        //ans[0]: nums1-nums2\n        for(int i=0; i<nums1.size(); i++)\n        {\n            if (find(nums2.begin(), nums2.end(), nums1[i]) == nums2.end() && find(ans[0].begin(), ans[0].end(), nums1[i])==ans[0].end())\n                \n                ans[0].push_back(nums1[i]);\n        }\n        \n        \n        //ans[1]: nums2-nums1\n        for(int i=0; i<nums2.size(); i++)\n        {\n            if (find(nums1.begin(), nums1.end(), nums2[i]) == nums1.end()  && find(ans[1].begin(), ans[1].end(), nums2[i])== ans[1].end())\n                \n                ans[1].push_back(nums2[i]);\n        }\n        \n        return ans;\n    }\n};\n```
['C', 'Ordered Set']