[Swiftアルゴリズム]分割された数値配列

514 ワード

https://programmers.co.kr/learn/courses/30/lessons/12910
func solution(_ arr:[Int], _ divisor:Int) -> [Int] {
    
    var collection : [Int] = []
    
    for i in arr {
        if i % divisor == 0 {
            collection.append(i)
        }
    }
    
    if collection.count == 0 {
        collection.append(-1)
    }
    
    return collection.sorted()
}