leetpycode/easy/clear_digits.py

13 lines
312 B
Python

# https://leetcode.com/problems/clear-digits
class Solution:
def clearDigits(self, s: str) -> str:
stack = []
for i in range(len(s)):
if '0' <= s[i] and s[i] <= '9':
stack.pop()
else:
stack.append(s[i])
return ''.join(stack)