题目
Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.
Note:
- The length of num is less than 10002 and will be ≥ k.
- The given num does not contain any leading zero.
Example 1:
1 | Input: num = "1432219", k = 3 |
Example 2:
1 | Input: num = "10200", k = 1 |
Example 3:
1 | Input: num = "10", k = 2 |
思路
维护一个保持递增顺序的栈。
代码
1 | class Solution(object): |