Given a non-negative integer n that contains at least one digit 5, remove exactly one occurrence of the digit 5 from its decimal representation so that the resulting number is as large as possible.
Return the maximum possible integer after the deletion. The result must not contain leading zeros, unless the result itself is zero.
Function Signature
def delete_five_for_max(n: int) -> int:
Rules
-
Exactly one
5
is deleted. No other digit is removed, added or moved.
-
The return value is an integer, so any leading zeros left after the deletion are dropped. Deleting the
5
from
5072
gives
72
.
-
If
n
is the single digit
5
, nothing is left after the deletion and the result is
0
.
Constraints
-
0 <= n <= 10^18
-
n
contains at least one occurrence of the digit
5
in its decimal representation.
Examples
Input: n = 15958
Output: 1958
The digits are 1, 5, 9, 5, 8. Deleting the first 5 gives 1958 and deleting the second gives 1598, so the answer is 1958.
Input: n = 50515
Output: 5051
The three possible deletions give 0515 (which is 515), 5015 and 5051. The largest is 5051.
Input: n = 5
Output: 0
The only digit is 5. Removing it leaves an empty string, which represents 0.