2259. Remove Digit From Number to Maximize Result
Question
You are given a string number
representing a positive integer and a character digit
.
Return the resulting string after removing exactly one occurrence of digit
from number
such that the value of the resulting string in decimal form is maximized. The test cases are generated such that digit
occurs at least once in number
.
Solution
按顺序比较当前等于digit的字符及下一个字符,如果当前字符小于后面的字符,则移除它是最优解。
Code
1 | class Solution { |
2259. Remove Digit From Number to Maximize Result
https://xuanhe95.github.io/2023/05/11/2259-Remove-Digit-From-Number-to-Maximize-Result/