java.lang.Object
g2201_2300.s2259_remove_digit_from_number_to_maximize_result.Solution

public class Solution extends Object
2259 - Remove Digit From Number to Maximize Result.<p>Easy</p> <p>You are given a string <code>number</code> representing a <strong>positive integer</strong> and a character <code>digit</code>.</p> <p>Return <em>the resulting string after removing <strong>exactly one occurrence</strong> of</em> <code>digit</code> <em>from</em> <code>number</code> <em>such that the value of the resulting string in <strong>decimal</strong> form is <strong>maximized</strong></em>. The test cases are generated such that <code>digit</code> occurs at least once in <code>number</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> number = &ldquo;123&rdquo;, digit = &ldquo;3&rdquo;</p> <p><strong>Output:</strong> &ldquo;12&rdquo;</p> <p><strong>Explanation:</strong> There is only one &lsquo;3&rsquo; in &ldquo;123&rdquo;. After removing &lsquo;3&rsquo;, the result is &ldquo;12&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> number = &ldquo;1231&rdquo;, digit = &ldquo;1&rdquo;</p> <p><strong>Output:</strong> &ldquo;231&rdquo;</p> <p><strong>Explanation:</strong> We can remove the first &lsquo;1&rsquo; to get &ldquo;231&rdquo; or remove the second &lsquo;1&rsquo; to get &ldquo;123&rdquo;.</p> <p>Since 231 > 123, we return &ldquo;231&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> number = &ldquo;551&rdquo;, digit = &ldquo;5&rdquo;</p> <p><strong>Output:</strong> &ldquo;51&rdquo;</p> <p><strong>Explanation:</strong> We can remove either the first or second &lsquo;5&rsquo; from &ldquo;551&rdquo;.</p> <p>Both result in the string &ldquo;51&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= number.length <= 100</code></li> <li><code>number</code> consists of digits from <code>'1'</code> to <code>'9'</code>.</li> <li><code>digit</code> is a digit from <code>'1'</code> to <code>'9'</code>.</li> <li><code>digit</code> occurs at least once in <code>number</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • removeDigit

      public String removeDigit(String number, char digit)