부족한 금액 계산하기
-
[프로그래머스][Swift] 부족한 금액 계산하기알고리즘 2022. 7. 1. 17:58
import Foundation func solution(_ price:Int, _ money:Int, _ count:Int) -> Int64{ var answer: Int64 = 0 for n in 1...count { answer += Int64(price * n) } if answer - Int64(money) > 0 { return answer - Int64(money) } return 0 } 고차함수 복습하고 다시 풀어봄 import Foundation func solution(_ price:Int, _ money:Int, _ count:Int) -> Int64{ var sum = (1...count).map { $0 * price }.reduce(0) { $0 + $1 } return mone..