|
| 1 | +<h2><a href="https://leetcode.com/problems/remove-digit-from-number-to-maximize-result">2337. Remove Digit From Number to Maximize Result</a></h2><h3>Easy</h3><hr><p>You are given a string <code>number</code> representing a <strong>positive integer</strong> and a character <code>digit</code>.</p> |
| 2 | + |
| 3 | +<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> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> number = "123", digit = "3" |
| 10 | +<strong>Output:</strong> "12" |
| 11 | +<strong>Explanation:</strong> There is only one '3' in "123". After removing '3', the result is "12". |
| 12 | +</pre> |
| 13 | + |
| 14 | +<p><strong class="example">Example 2:</strong></p> |
| 15 | + |
| 16 | +<pre> |
| 17 | +<strong>Input:</strong> number = "1231", digit = "1" |
| 18 | +<strong>Output:</strong> "231" |
| 19 | +<strong>Explanation:</strong> We can remove the first '1' to get "231" or remove the second '1' to get "123". |
| 20 | +Since 231 > 123, we return "231". |
| 21 | +</pre> |
| 22 | + |
| 23 | +<p><strong class="example">Example 3:</strong></p> |
| 24 | + |
| 25 | +<pre> |
| 26 | +<strong>Input:</strong> number = "551", digit = "5" |
| 27 | +<strong>Output:</strong> "51" |
| 28 | +<strong>Explanation:</strong> We can remove either the first or second '5' from "551". |
| 29 | +Both result in the string "51". |
| 30 | +</pre> |
| 31 | + |
| 32 | +<p> </p> |
| 33 | +<p><strong>Constraints:</strong></p> |
| 34 | + |
| 35 | +<ul> |
| 36 | + <li><code>2 <= number.length <= 100</code></li> |
| 37 | + <li><code>number</code> consists of digits from <code>'1'</code> to <code>'9'</code>.</li> |
| 38 | + <li><code>digit</code> is a digit from <code>'1'</code> to <code>'9'</code>.</li> |
| 39 | + <li><code>digit</code> occurs at least once in <code>number</code>.</li> |
| 40 | +</ul> |
0 commit comments