找出数组中重复的数字-golang
找出数组中重复的数字-golang
func duplicateInArray(nums []int) int {
n := len(nums)
for _, v := range nums{
if v <0 || v >= n{
return -1
}
}
for i := 0; i < n; i++{
for nums[i] != nums[nums[i]]{
nums[i], nums[nums[i]] = nums[nums[i]], nums[i]
}
if nums[i] != i{
return nums[i]
}
}
return -1
}