C++ Sorting + Greedy
\n\nSee my latest update in repo LeetCode\n\n## Solution 1. Sorting + Greedy\n\nGet the 4 digits from n. Assume they are a <= b <= c <= d, the sum is minimum wh
\n\nSee my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Sorting + Greedy\n\nGet the 4 digits from `n`. Assume they are `a <= b <= c <= d`, the sum is minimum when `new1 = ac` and `new2 = bd`.\n\nSo, the answer is `10 * (a + b) + (c + d)`.\n\n```cpp\n// OJ: https://leetcode.com/contest/biweekly-contest-71/problems/minimum-sum-of-four-digit-number-after-splitting-digits/\n// Author: github.com/lzl124631x\n// Time: O(1) or more specifically, O(KlogK), where `K` is the number of digits in `n`\n// Space: O(1) or O(K)\nclass Solution {\npublic:\n    int minimumSum(int n) {\n        int d[4] = {};\n        for (int i = 0; i < 4; ++i, n /= 10) d[i] = n % 10;\n        sort(begin(d), end(d));\n        return 10 * (d[0] + d[1]) + d[2] + d[3];\n    }\n};\n```
[]