Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def removeKdigits(self, num: str, k: int) -> str:
- if len(num) == k:
- return '0'
- st = []
- i = 0
- for d in num:
- while k and st and st[-1] > d:
- st.pop()
- k -= 1
- st.append(d)
- end = len(st) - k
- start = 0
- while st and start < len(st) and st[start] == '0':
- start += 1
- return ''.join(st[start:end]) if end > start else '0'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement