1
class Solution:
2
def removeDigit(self, number: str, digit: str) -> str:
3

4
# Initializing the last index as zero
5
last_index = 0
6

7
# iterating each number to find the occurences, \
8
# and to find if the number is greater than the next element \
9

10
for num in range(1, len(number)):
11

12
# Handling [case 1] and [case 2]
13
if number[num - 1] == digit:
14
if int(number[num]) > int(number[num - 1]):
15
return number[: num - 1] + number[num:]
16
else:
17
last_index = num - 1
18

19
# If digit is the last number (last occurence) in the string [case 3]
20
if number[-1] == digit:
21
last_index = len(number) - 1
22

23
return number[:last_index] + number[last_index + 1 :]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0