-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
💬 문제
https://school.programmers.co.kr/learn/courses/30/lessons/42746
💬 Idea
- sorted(by:) 메서드를 응용하는 방법에 대해서 더 깊이 알게 되었다.
- 두 수를 더한 합이 더 크도록 정렬하면 되는 문제였다.!!!!!!!
💬 풀이
import Foundation
func solution(_ numbers:[Int]) -> String {
let arr = numbers.sorted(by: { Int(String($0) + String($1))! > Int(String($1) + String($0))! })
if arr.allSatisfy({ $0 == 0 }) {
return "0"
} else {
return arr.map({ String($0) }).joined()
}
}