[PRO][Lv.1] 예산

김정현·2023년 1월 11일
0

프로그래머스

목록 보기
35/50

📚 Problem

예산

💫 Solve

import Foundation

func solution(_ d:[Int], _ budget:Int) -> Int {
    var arr : [Int] = d
    arr.sort()
    var total = budget
    var num = 0
    for i in arr {
        total -= i
        if total >= 0 {
            num += 1
            continue
        }
        return num
        
    }
     return num
}

🩺 Another Solution


import Foundation

func solution(_ d:[Int], _ budget:Int) -> Int {
    var budget = budget

    return d.sorted().filter{
        budget = budget - $0
        return budget >= 0
    }.count
}
profile
🍎💻👍

0개의 댓글