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