<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p>

<ul>
	<li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which are <strong>not</strong> present in</em> <code>nums2</code><em>.</em></li>
	<li><code>answer[1]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums2</code> <em>which are <strong>not</strong> present in</em> <code>nums1</code>.</li>
</ul>

<p><strong>Note</strong> that the integers in the lists may be returned in <strong>any</strong> order.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [1,2,3], nums2 = [2,4,6]
<strong>Output:</strong> [[1,3],[4,6]]
<strong>Explanation:
</strong>For nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].
For nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [1,2,3,3], nums2 = [1,1,2,2]
<strong>Output:</strong> [[3],[]]
<strong>Explanation:
</strong>For nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].
Every integer in nums2 is present in nums1. Therefore, answer[1] = [].
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums1.length, nums2.length &lt;= 1000</code></li>
	<li><code>-1000 &lt;= nums1[i], nums2[i] &lt;= 1000</code></li>
</ul>

class Solution {
public:
    vector<int> removeDuplicates(vector<int>& num) {
        vector<int> ans;
        if (num.size() == 0) return ans;

        int lastNum = num[0];
        ans.push_back(lastNum);
        for (int i = 1; i < num.size(); ++i) {
            if (num[i] != lastNum) {
                ans.push_back(num[i]);
                lastNum = num[i];
            }
        }
        return ans;
    }

    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {
        // union two arrays and remove elements from union from each array

        // sort array
        sort(nums1.begin(), nums1.end());
        sort(nums2.begin(), nums2.end());

        // remove duplicates
        vector<int> int1 = removeDuplicates(nums1);
        vector<int> int2 = removeDuplicates(nums2);

        vector<vector<int>> results;
        vector<int> ans1, ans2;

        // prune shared values
        int n1 = 0, n2 = 0;
        while (n1 < int1.size() && n2 < int2.size()) {
            if (int1[n1] != int2[n2]) {
                if (int1[n1] < int2[n2]) {
                    ans1.push_back(int1[n1]);
                    n1++;
                } else {
                    ans2.push_back(int2[n2]);
                    n2++;
                }
            } else {
                n1++;
                n2++;
            }
        }

        if (n1 != int1.size()) for (int i = n1; i < int1.size(); ++i) ans1.push_back(int1[i]);
        if (n2 != int2.size()) for (int i = n2; i < int2.size(); ++i) ans2.push_back(int2[i]);

        results.push_back(ans1);
        results.push_back(ans2);

        return results;
    }
};
31744