I found a very impressive solution in the youtube. Check this: https://www.youtube.com/watch?v=HuZJqRDOPo0

```
class Solution {
public:
int findDuplicate(vector<int>& nums) {
for ( int i = 0; i < nums.size(); i++ ) {
int index = abs(nums[i]);
if ( nums[index] > 0 ) {
nums[index] = -nums[index];
} else return index;
}
}
};
```