[프로그래머스 LV0] 자릿수 더하기

jonghwan·2022년 10월 5일
0

프로그래머스

목록 보기
20/71
post-thumbnail

1. 문제 설명

자릿수 더하기

2. 문제 분석

문자로 바꿔서 map으로 나눈 다음 다시 숫자로 바꿔서 차례로 더하기

3. 나의 풀이

import Foundation

func solution(_ n:Int) -> Int {
    return String(n).map{ Int(String($0))! }.reduce(0, +) 
}

0개의 댓글