[Swift 알고리즘] 나누어 떨어지는 숫자 배열

장주명·2021년 5월 11일
0

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()
}
profile
flutter & ios 개발자

0개의 댓글

관련 채용 정보