leetcode 402. Remove K Digits】的更多相关文章

402. Remove K Digits https://www.cnblogs.com/grandyang/p/5883736.html https://blog.csdn.net/fuxuemingzhu/article/details/81034522 https://blog.csdn.net/qq508618087/article/details/52584133 题目的要求是删除k个字符,在保证原字符串字符相对位置不变的情况下获得最小的数字. 一个贪心的思想,维护一个单调递增的栈.只…
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. Ex…
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. Ex…
[LeetCode]402. Remove K Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-k-digits/description/ 题目描述: Given a non-negative integer num represented as a string, rem…
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. Ex…
题目如下: 解题思路:我的方法是从头开始遍历num,对于任意一个num[i],在[i+1~len(num)-1]区间内找出离num[i]最近并且小于num[i]的数num[j],如果j-i <= k的话表示num[j]可以被删除,同时记k -= 1:如果找不到num[j]或者j-i > k则表示不能被删除.如果num遍历完成,但是k>0的话,把num最后k个字符删除,即为最终结果. 代码如下: class Solution(object): def getNearbyMin(self,d…
(English version is after the code part) 这个题做起来比看起来容易,然后我也没仔细想,先速度刷完,以后再看有没有改进. 用这个来说: 1 2 4 3 2 2 1 9 去掉1位的话,应该去掉4,得到 1 2 3 2 2 1 9 去掉2位的话,在刚才的基础上,去掉3,得到1 2 2 2 1 9. 显而易见,每次找第一个最大值.上面的例子,第一次找到的是4,第二次是3,下一个数开始变小就不找了,所以找不到最后的9. 然后就各种特殊情况. 首先例子已经给了一个提示…
给定一个以字符串表示的非负整数 num,移除这个数中的 k 位数字,使得剩下的数字最小.注意:    num 的长度小于 10002 且 ≥ k.    num 不会包含任何前导零.示例 1 :输入: num = "1432219", k = 3输出: "1219"解释: 移除掉三个数字 4, 3, 和 2 形成一个新的最小的数字 1219.示例 2 :输入: num = "10200", k = 1输出: "200"解释:…
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. Ex…
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. Ex…