You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.

You are given an integer array nums representing the data status of this set after the error.

Find the number that occurs twice and the number that is missing and return them in the form of an array.

&nbsp;
Example 1:
Input: nums = [1,2,2,4]
Output: [2,3]
Example 2:
Input: nums = [1,1]
Output: [1,2]

&nbsp;
Constraints:


	2 &lt;= nums.length &lt;= 104
	1 &lt;= nums[i] &lt;= 104


class Solution {
public:
    vector<int> findErrorNums(vector<int>& nums) 
    {
        unordered_map<int,int> m;
        int p,q;
        for(auto &x:nums)
        {
            m[x]++;
            if(m[x]==2)
            {
                p=x;
                break;
            }
        }
        int n=nums.size();
        q=(n*(n+1))/2-accumulate(nums.begin(),nums.end(),0)+p;
        return {p,q};
        
    }
};
// if you like the solution plz upvote.
class Solution {
    public int[] findErrorNums(int[] nums) {
        int n = nums.length;
        int dup = 0, miss = 0;

        for (int i = 1; i <= n; i++) {
            int count = 0;
            for (int j = 0; j < n; j++) {
                if (nums[j] == i) count++;
            }

            if (count == 2) dup = i;
            if (count == 0) miss = i;
        }

        return new int[] {dup, miss};
    }
}

// TC: O(n ^ 2), SC: O(1)
class Solution {
public:
    vector<int> findErrorNums(vector<int>& nums)
    {
        unordered_map<int,int> m;
        int p,q;
        for(auto &x:nums)
        {
            m[x]++;
            if(m[x]==2)
            {
                p=x;
                break;
            }
        }
        int n=nums.size();
        q=(n*(n+1))/2-accumulate(nums.begin(),nums.end(),0)+p;
        return {p,q};

    }
};
// if you like the solution plz upvote.
class Solution {
public:
    vector<int> findErrorNums(vector<int>& nums) 
    {
        unordered_map<int,int> m;
        int p,q;
        for(auto &x:nums)
        {
            m[x]++;
            if(m[x]==2)
            {
                p=x;
                break;
            }
        }
        int n=nums.size();
        q=(n*(n+1))/2-accumulate(nums.begin(),nums.end(),0)+p;
        return {p,q};
        
    }
};
// if you like the solution plz upvote.
Set Mismatch