```
public class Solution {
public int findDuplicate(int[] nums) {
int answer = -1;
for(int i = 0; i < nums.length; i++){
int value = Math.abs(nums[i]) - 1;
if(nums[value] > 0){
nums[value] = -nums[value];
}
else{
answer = nums[i];
}
}
return Math.abs(answer);
}
}
```