public int findDuplicate(int[] nums) {

if (nums.length > 1) {

for (int i = 0; i < nums.length; i++) {

if (nums[Math.abs(nums[i])] >= 0)

nums[Math.abs(nums[i])] = -nums[Math.abs(nums[i])];

else

return Math.abs(nums[i]); // Here we can create a list of duplicates in case we have to track multiple duplicate entries in the items.

}

}

return -1;

}