class Solution {
public:
int duplicateInArray(vector<int>& nums) {
int len = nums.size();
int ele = len;
for (int i=0;i<len;i++){
int x = nums[i];
if (x >= len || x < 0){
return -1;
}
}
for (int i=0;i<len;i++){
while(1){
int x = nums[i];
if (x == i){
break;
}
if (x != nums[x] ){
int temp = nums[i];
nums[i] = nums[x] ;
nums[x] = temp;
continue;
}
else{
return x;
}
}
}
return -1;
}
};