Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.
- '''
- class Solution:
- def removeKdigits(self, num: str, k: int) -> str:
- st=[]
- if len(num)==1 and k==1:return '0'
- n=len(num)
- for i in num:
- while st and st[-1]>i and k>0:
- k-=1
- st.pop()
- if st or i!='0':
- st.append(i)
- t=''.join(st)
- if k:t=t[:-k]
- return '0' if not t else t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement