func firstDuplicateIn (array: [Int]) -> Int {
var array2 = Int
for i in 0..<array.count {
if array2.contains(array[i]) {
return array[i]
} else {
array2.append(array[i])
}
}
return -1
}
print(firstDuplicateIn(array: array))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
let array = [2, 1, 3, 5, 3, 2]
func firstDuplicateIn (array: [Int]) -> Int {
var array2 = Int
for i in 0..<array.count {
if array2.contains(array[i]) {
return array[i]
} else {
array2.append(array[i])
}
}
return -1
}
print(firstDuplicateIn(array: array))