[Codility] Duplicate Item in array

func solution(arr:[Int])->Int{
    
var dup:Int = -1

for i in arr{
    let dupInt:[Int]  = arr.filter{ $0 == i }
    if dupInt.count > 1 {
        dup = i
        break
        }
    }
    return dup
}

你可能感兴趣的:([Codility] Duplicate Item in array)