打卡题目:leetcode第402题,移掉K位数字
相似题目:738
【代码】
class Solution:def removeKdigits(self, num: str, k: int) -> str:# 单调栈stack = []for digit in num:while k and stack and digit < stack[-1]:stack.pop()k -= 1stack.append(digit)final_stack = stack[:-k] if k else stackreturn "".join(final_stack).lstrip('0') or "0"
