int num[1005];
class Solution {
public:
int duplicateInArray(vector<int>& nums) {
memset(num,0,sizeof(num));
int len = nums.size(),now = 0,flag = 0;
for(int i = 0;i < len;i ++)
{
int j = nums[i];
if(nums[i] < 0 || nums[i] >= len) return -1;
if(num[j] && !flag) now = j,flag = 1;
else num[j] ++;
}
if(flag) return now;
else return -1;
}
};