321. Create Maximum Number】的更多相关文章

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…
321. Create Maximum Number 题目描述 Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the digits from the same array must be preserved…
/* * 321. Create Maximum Number * 2016-7-6 by Mingyang */ public int[] maxNumber(int[] nums1, int[] nums2, int k) { int n = nums1.length; int m = nums2.length; int[] ans = new int[k]; for (int i = Math.max(0, k - m); i <= k && i <= n; ++i) {…
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 two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the digits from the same array must be preserved. Return an array of the k digit…
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the digits from the same array must be preserved. Return an array of the k digit…
原题链接在这里:https://leetcode.com/problems/create-maximum-number/description/ 题目: Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + nfrom digits of the two. The relative order of the…
已知长度分别为 m 和 n 的两个数组,其元素由 0-9 构成,直观地表示两个自然数各位上的数字.现在从这两个数组中选出 k (k <= m + n) 个数字拼接成一个新的数,要求从同一个数组中取出的数字保持其在原数组中的相对顺序.求满足该条件的最大数.结果返回一个表示该最大数的长度为k的数组.尽可能优化你的算法的时间和空间复杂度.例 1:nums1 = [3, 4, 6, 5]nums2 = [9, 1, 2, 5, 8, 3]k = 5返回 [9, 8, 6, 5, 3]例 2:nums1…
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the digits from the same array must be preserved. Return an array of the k digit…
leetcode 321 Create Max Number greedy的方法,由于有两个数组,我们很自然的想到从数组1中选i个数,数组2中选k-i个数,这样我们只需要遍历max(0, k-数组2长度n) ~ 数组1长度,然后保存合并i和k-i这两个部分之后得到的最大值即可. 那么还剩下这几个问题: 1) 从一个数组中不改变元素顺序地选出i个元素,使他们顺序排列代表的十进制数最大.例:[1,4,3,6,2], i = 3, 结果为[4,6,2] 2) 如何合并数组1的i个元素和数组2的k-i个…