$T(n) = O(n), S(n) = O(1)$
class Solution {
public int duplicateInArray(int[] nums) {
int len = nums.length;
for (int num : nums) {
if (num < 0 || num >= len) {
return -1;
}
}
for (int i = 0; i < len; i++) {
while (nums[i] != i) {
if (nums[i] == nums[nums[i]]) {
return nums[i];
}
int temp = nums[i];
nums[i] = nums[temp];
nums[temp] = temp;
}
}
return -1;
}
}