Class Solution
-
- All Implemented Interfaces:
public final class Solution2259 - Remove Digit From Number to Maximize Result.
Easy
You are given a string
numberrepresenting a positive integer and a characterdigit.Return the resulting string after removing exactly one occurrence of
digitfromnumbersuch that the value of the resulting string in decimal form is maximized. The test cases are generated such thatdigitoccurs at least once innumber.Example 1:
Input: number = "123", digit = "3"
Output: "12"
Explanation: There is only one '3' in "123". After removing '3', the result is "12".
Example 2:
Input: number = "1231", digit = "1"
Output: "231"
Explanation: We can remove the first '1' to get "231" or remove the second '1' to get "123".
Since 231 > 123, we return "231".
Example 3:
Input: number = "551", digit = "5"
Output: "51"
Explanation: We can remove either the first or second '5' from "551".
Both result in the string "51".
Constraints:
2 <= number.length <= 100numberconsists of digits from'1'to'9'.digitis a digit from'1'to'9'.digitoccurs at least once innumber.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringremoveDigit(String number, Character digit)-
-
Method Detail
-
removeDigit
final String removeDigit(String number, Character digit)
-
-
-
-