• 26.1%

https://leetcode.com/problems/remove-k-digits/description/

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.

https://discuss.leetcode.com/topic/59871/two-algorithms-with-detailed-explaination

Two algorithms with detailed explaination

The first algorithm is straight-forward. Let’s think about the simplest case: how to remove 1 digit from the number so that the new number is the smallest possible？ Well, one can simply scan from left to right, and remove the first “peak” digit; the peak digit is larger than its right neighbor. One can repeat this procedure k times, and obtain the first algorithm:

The above algorithm is a bit inefficient because it frequently remove a particular element from a string and has complexity O(k* n).

One can simulate the above procedure by using a stack, and obtain a O(n) algorithm. Note, when the result stack (i.e. res) pop a digit, it is equivalent as remove that “peak” digit.

https://discuss.leetcode.com/topic/59412/a-greedy-method-using-stack-o-n-time-and-o-n-space

A greedy method using stack, O(n) time and O(n) space

#### python

52ms, September 19, 2016

https://discuss.leetcode.com/topic/59380/short-python-one-o-n-and-one-regex

272ms, September 19, 2016

https://discuss.leetcode.com/topic/59380/short-python-one-o-n-and-one-regex