LintCode Delete Digits

Given string A representative a positive integer which has N digits, remove any k digits of the number, the remaining digits are arranged according to the original order to become a new positive integer. Find the smallest integer after remove k digits. N <= 240 and k <= N,

维护一个stack,每次把当前char加进去,直到加到A.length()-k个。加之前看看能不能删一些栈顶元素,条件:

  1. 栈非空
  2. 当前元素<栈顶元素
  3. A后面剩的元素数目 >= A.length()-k-stack.size() 这样弄出来栈里面存着最后的数 注意可能以0开头,没关系,因为题目是删掉元素剩的最小的数,允许的,只用最后返回结果把开头0去掉就行