Class Solution

java.lang.Object
g2501_2600.s2578_split_with_minimum_sum.Solution

public class Solution extends Object
2578 - Split With Minimum Sum.<p>Easy</p> <p>Given a positive integer <code>num</code>, split it into two non-negative integers <code>num1</code> and <code>num2</code> such that:</p> <ul> <li>The concatenation of <code>num1</code> and <code>num2</code> is a permutation of <code>num</code>. <ul> <li>In other words, the sum of the number of occurrences of each digit in <code>num1</code> and <code>num2</code> is equal to the number of occurrences of that digit in <code>num</code>.</li> </ul> </li> <li><code>num1</code> and <code>num2</code> can contain leading zeros.</li> </ul> <p>Return <em>the <strong>minimum</strong> possible sum of</em> <code>num1</code> <em>and</em> <code>num2</code>.</p> <p><strong>Notes:</strong></p> <ul> <li>It is guaranteed that <code>num</code> does not contain any leading zeros.</li> <li>The order of occurrence of the digits in <code>num1</code> and <code>num2</code> may differ from the order of occurrence of <code>num</code>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> num = 4325</p> <p><strong>Output:</strong> 59</p> <p><strong>Explanation:</strong> We can split 4325 so that <code>num1</code> is 24 and num2 <code>is</code> 35, giving a sum of 59. We can prove that 59 is indeed the minimal possible sum.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> num = 687</p> <p><strong>Output:</strong> 75</p> <p><strong>Explanation:</strong> We can split 687 so that <code>num1</code> is 68 and <code>num2</code> is 7, which would give an optimal sum of 75.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>10 <= num <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • splitNum

      public int splitNum(int number)