```
public int findDuplicate(int[] nums) {
for (int i = 0; i < nums.length; i++) {
int abs = Math.abs(nums[i]);
if (nums[abs] < 0) {
return abs;
}
nums[abs] = -nums[abs];
}
return 0;
}
```