[PRO][Lv.1] 없는 숫자 더하기

김정현·2022년 12월 19일
0

프로그래머스

목록 보기
16/50

📚 Problem

없는 숫자 더하기

💫 Solve

import Foundation

func solution(_ numbers:[Int]) -> Int {
    var total : Int = 0
    for i in numbers {
        total += i
    }
    
    return 45 - total
}

🩺 Another Solution

import Foundation

func solution(_ numbers:[Int]) -> Int {
    return 45-numbers.reduce(0, +)
}
profile
🍎💻👍

0개의 댓글