새소식

인기 검색어

프로그래머스/Lv.1

[Swift] 기사단원의 무기

  • -
import Foundation

func solution(_ number:Int, _ limit:Int, _ power:Int) -> Int {
    
    var attack = [Int](repeating: 0, count: number+1)

    for i in 1...number {
        var c = i
        while c <= number {
            attack[c] += 1
            c += i
        }
        print(attack)
    }
    attack = attack.map { $0 > limit ? power : $0 }
    return attack.reduce(0, +)
}

 

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.