LeetCode – 2160. Minimum Sum of Four Digit Number After Splitting Digits

題目連結:

https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/

參考解法:

https://blog.csdn.net/qq_45124566/article/details/124070992

    func minimumSum(_ num: Int) -> Int {
        var arr: [Int] = []
        var tmp = num
        while tmp > 0 {
            let val = tmp % 10
            arr.append(val)
            tmp = tmp / 10
        }

        arr.sort(by: <)

        return (arr[0] + arr[1]) * 10 + (arr[2] + arr[3])
    }