```
public int findDuplicate(int[] nums) {
for (int i = 0; i< nums.length; i++){
int value = nums[i];
int start = 0;
int end = nums.length-1;
while (start < end){
if(((i != start) && (nums[start] == value)) || ((i != end) && (nums[end] == value))){
return value;
} else {
start++;
end --;
}
}
}
return -1;
}
```