The idea is using array indexing, that is putting each `nums[i]`

into the position with index `nums[i] - 1`

. Then, the array becomes [1,2,3,4,5...,n]. So we can find the duplicate number when `nums[i] != i+1`

.

```
vector<int> findErrorNums(vector<int>& nums) {
for(int i = 0; i<nums.size(); i++){
while(nums[i] != nums[nums[i] - 1])swap(nums[i], nums[nums[i] - 1]);
}
for(int i = 0; i<nums.size() ; i++){
if(nums[i] != i + 1)return {nums[i], i + 1};
}
}
```