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

<p>You are given an integer array <code>nums</code> representing the data status of this set after the error.</p>

<p>Find the number that occurs twice and the number that is missing and return <em>them in the form of an array</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> nums = [1,2,2,4]
<strong>Output:</strong> [2,3]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums = [1,1]
<strong>Output:</strong> [1,2]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution {
public:
    vector<int> findErrorNums(vector<int>& nums) {
        vector<int>res;
        sort(nums.begin(),nums.end());
        int d=0,m=0;
        int  n=nums.size();
        vector<int> ct(n+1 ,0);
        for(int i=0;i<n;i++)
            ct[nums[i]]++;
        for(int i=1;i<=n;i++){
            if(ct[i]==0)
              m=i;

            if(ct[i]==2)
               d=i;
        }

        res.push_back(d);
       res.push_back(m);
       return res;
        
        /*
       int d=-1, df=1;
       int m=-1,mf=1;
       int k=1;
       for(int i=0;i<nums.size()-1;i++){
        if(nums[i]==nums[i+1] &&df){
            d=nums[i];
            df=0;
        }
        if(nums[i]!=k && mf){
            cout<<i<<" ";
            m=k;
            mf=0;
        }
        else if(nums[i]==k && mf && !df)
        {
            m=k+1;
            mf=0;
        }
        k++;
       }
       
       res.push_back(d);
       res.push_back(m);
       return res;
       */

        /*
        int prev=nums[0];
        for(int i=0;i<nums.size()-1;i++)
        {
            cout<<prev<<" ";
            if((nums[i]^nums[i+1]) == 0){
                if((nums[i]-prev ==2) && prev>1){
                res.push_back(nums[i]);
                
                res.push_back(nums[i]-1);
                break;
                }
                else{
                    res.push_back(nums[i]);
                
                res.push_back(nums[i]+1);
                break;

                }
            
            }
            prev=nums[i];
        }*/
        /*
        int y=1;
        for(int i=0;i<nums.size();i++){
            if(nums[i]==y){
                y++;
            }
            else{
                res.push_back(nums[i]);
                
                res.push_back(y);
                 break;
            }

        }
        return res;
        */
        
    }
};
25700