This question is very similar like: 448. Find All Numbers Disappeared in an Array

```
class Solution {
public:
vector<int> findDuplicates(vector<int>& nums) {
vector<int> res;
if(nums.empty()) return res;
for(int i = 0; i < nums.size(); ++i){
while(nums[nums[i] - 1] != nums[i]){
swap(nums[nums[i] - 1], nums[i]);
}
}
for(int i = 0; i < nums.size(); ++i){
if(nums[i] != i + 1){
res.push_back(nums[i]);
}
}
return res;
}
};
```