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.
給予一個非負數num用一個字串去表示,移除掉k個位元讓新的數字越小越好。
注意:
- num的長度小於10002且會 ≥ k。
- 給予的num不會有零在開頭。
i
個位元大於i + 1
個位元,那我們就移除掉i
。
1432
,就移除4
。102
,移除1
會變成02
,無條件移除0
(k
不需要變)。i
比i + 1
大,那麼就移除最低位元(因為它數字最大)
12345
,就移除5
。num
已經空了,補一個0
然後直接回傳。LeetCode
C++