[PRO][Lv.1] 콜라 문제

김정현·2023년 1월 16일
0

프로그래머스

목록 보기
37/50

📚 Problem

콜라 문제

💫 Solve

import Foundation

func solution(_ a:Int, _ b:Int, _ n:Int) -> Int {
    var rest : Int = n
    var total : Int = 0
    
    while rest >= a {
       total += (rest / a) * b
       rest =  (rest / a) * b + rest % a
    }
    return total
}

🩺 Another Solution

func solution(_ a:Int, _ b:Int, _ n:Int) -> Int {
    return (n > b ? n - b : 0) / (a - b) * b
}

이게 도대체..사람뇌에서 나올수 있는건가

profile
🍎💻👍

0개의 댓글