Secondly, we check through the array. If a number x doesn't present in nums[x - 1], then x is absent.

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

]]>Secondly, we check through the array. If a number x doesn't present in nums[x - 1], then x is absent.

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

]]>are u sure it is right ?

try {3,2,5,4,3}

]]>oh i forgot ,that int i is not been increased ]]>

nums[nums[i]-1]

does?? ]]>

I know that nums[i] is gonna tell us the the ith value in nums, but what nums[nums[i]-1] is gonna tell us?

I apologize if this is kinda a bad question, im just a super beginner. ]]>

Is that a O(n) solution?

Really interesting, seems like in worst case it'll be O(n^2) solution, but it's runtime beats 76% solutions

Can anyone suggest some facts about this algorithm's complexity

]]>Could you do it without extra space and in O(n) runtime?

]]>"we check through the array. If a number x doesn't present in nums[x - 1], then x is absent." and nums[x-1] is a duplicate value so we add it to the res vector.

]]>