```
vector<int> findDuplicates(vector<int>& nums) {
vector<int> res;
for(int x : nums) if((nums[abs(x)-1]*=-1) > 0) res.push_back(abs(x));
return res;
}
```

or

```
vector<int> findDuplicates(vector<int>& nums) {
vector<int> res; int k = 0;
for (int& x:nums) while (x != nums[x-1]) swap(x, nums[x-1]);
for (int& x:nums) if (x != ++k) res.push_back(x);
return res;
}
```