Remove One Five for the Largest Number
Problem statement
Given the canonical decimal representation of an integer as a string number, remove exactly one occurrence of the digit 5 and return the canonical decimal representation of the largest integer obtainable.
The input may begin with -. Strip leading zeros from the result, and return 0 when every remaining digit is zero or no digit remains.
Function
removeOneFive(number: String) → StringExamples
Example 1
number = "5456"return = "546"Removing the first 5 gives 456; removing the second gives 546, which is larger.
Example 2
number = "-5155"return = "-155"Among negative candidates, the one with the smallest magnitude is largest.
Constraints
1 <= number.length <= 17.- The input is a valid canonical decimal integer and contains at least one digit
5. - The result fits in a signed 64-bit integer.