```
class Solution {
public:
vector<int> findDuplicates(vector<int>& nums) {
// calculte size of vector
int n = nums.size();
for(int i=0;i<n;i++){
// swap till all nums[i] come to their original places
while(nums[i]!=nums[nums[i]-1]) swap(nums[i],nums[nums[i]-1]);
}
vector<int> ans;
// all elements which are between 1 and n come to their original places so we can skip those
for(int i=0;i<n;i++){
if(nums[i]!=i+1) ans.push_back(nums[i]);
}
return ans;
}
};
```