Find Repeat Number 2021-06-24 04:10
public static int findRepeatNumber(int[] nums) {
for (int i = 0; i < nums.length; i++) {
while(nums[i]!=i){
if (nums[nums[i]] != nums[i]) {
int temp = nums[i];
nums[i] = nums[temp];
nums[temp] = temp;
} else {
return nums[i];
}
}
}
return -1;
}
Runtime | Memory |
---|---|
0 ms | 46 MB |
EOF