03 2020 档案
摘要:问题:求是否给定的数列为一个山形数列(先单调增,再单调减) Example 1: Input: [2,1] Output: false Example 2: Input: [3,5,5] Output: false Example 3: Input: [0,3,2,1] Output: true N
阅读全文
摘要:问题: 求一个数列中的,最大嵌套子数列长度 Example 1: Input: A = [5,4,0,3,1,6,2] Output: 4 Explanation: A[0] = 5, A[1] = 4, A[2] = 0, A[3] = 3, A[4] = 1, A[5] = 6, A[6] =
阅读全文
摘要:问题: 求未排序数列中,最长连续数列长度。 Example: Input: [100, 4, 200, 1, 3, 2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefo
阅读全文
摘要:问题:求一个数列中,出现次数>n/3次的数字 Example 1: Input: [3,2,3] Output: [3] Example 2: Input: [1,1,1,3,3,2,2,2] Output: [1,2] 方法: 占权重法 出现次数>n/3,则可能出现最多两个结果。 将两个待选结果设
阅读全文
摘要:问题:求给定数列中,最短子数列,使子数列之和>=给定值s Example: Input: s = 7, nums = [2,3,1,2,4,3] Output: 2 Explanation: the subarray [4,3] has the minimal length under the pr
阅读全文
摘要:问题:求数组的任意峰值。两侧都从-∞开始向上递增。 Example 1: Input: nums = [1,2,3,1] Output: 2 Explanation: 3 is a peak element and your function should return the index numb
阅读全文
摘要:同https://www.cnblogs.com/habibah-chang/p/12538877.html 附加条件,允许重复数值。 Example 1: Input: [1,3,5] Output: 1 Example 2: Input: [2,2,2,0,1] Output: 0 方法: 思想
阅读全文
摘要:问题:求被旋转了的排序数列中的最小值。 Example 1: Input: [3,4,5,1,2] Output: 1 Example 2: Input: [4,5,6,7,0,1,2] Output: 0 方法:二分法查找 low=0,high=end index mid=low和high的中间值
阅读全文
摘要:问题: 给出给定数组的描述: Example 1: Input: [0,1,2,4,5,7] Output: ["0->2","4->5","7"] Explanation: 0,1,2 form a continuous range; 4,5 form a continuous range. Ex
阅读全文
摘要:问题:给定数组中,能否最多修改一个数,使得数组成为非减数组,即对数组中任意相邻两数:nums[i] <= nums[i+1] Example 1: Input: [4,2,3] Output: True Explanation: You could modify the first 4 to 1 t
阅读全文
摘要:问题: 处理给定数组,(平滑处理)使得每个元素=周围+自己共9个元素的平均值。(若没有9个元素,则是周围一圈+自己元素的平均值) Input: [[1,1,1], [1,0,1], [1,1,1]] Output: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] Explanat
阅读全文
摘要:问题: 求给定数组中,连续k个数的最大平均值。 Input: [1,12,-5,-6,50,3], k = 4 Output: 12.75 Explanation: Maximum average is (12-5-6+50)/4 = 51/4 = 12.75 Note: 1 <= k <= n <
阅读全文
摘要:问题:求一个数列里三个数相乘的最大值 Input: [1,2,3] Output: 6 Input: [1,2,3,4] Output: 24 Note: 1.The length of the given array will be in range [3,104] and all element
阅读全文
摘要:问题: 种花问题,在给出的花圃中(可能已经种植了一些花),如果存在空位与其他花相隔1个空位,则可在此处种植。 求:给出的花圃中,能否种植完给定数量的花。 Input: flowerbed = [1,0,0,0,1], n = 1 Output: True Input: flowerbed = [1,
阅读全文
摘要:问题: 求数列中最小的未排序子数列(即,如果将此子数列排序后,整个数列则成为有序数列) Input: [2, 6, 4, 8, 10, 9, 15] Output: 5 Explanation: You need to sort [6, 4, 8, 10, 9] in ascending order
阅读全文
摘要:Input: [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Input: [2,-5,-2,-4,3] Output: 24 Explanation: [-2,-4,3] has the largest prod
阅读全文
摘要:题目: 从1~9个数中,取k个数,使其和为n,求所有的组合 例子: Input: k = 3, n = 9 Output: [[1,2,6], [1,3,5], [2,3,4]] 方法: keyword:栈,递归 1. 对于1~9的每一个数, 用掉一个,则在剩下的数里面寻找满足的数。 2.结束条件:
阅读全文
摘要:题目:含有从1~n(数组size)数值的数组,里面存在重复元素,求缺掉的数字。 要求:不使用多余辅助空间,时间复杂度为(n)的算法 方法: 利用 原数组index 一一对应 所求连续数列的数值 的特点, 顺次遍历数组的同时,遇到某个值,使用正负号来标记已遇到。 最后在遍历一次,没遇到过的(即所求缺掉
阅读全文
摘要:题目:未排序的数组从0~n,依次增大的数列中缺少了一个数,是哪个? 方法一:高斯算法 等差数列求和,0~size()+1个数列的和 - 实际给定的数列的和 = 要求数字 参考代码: 1 class Solution { 2 public: 3 int missingNumber(vector<int
阅读全文
摘要:c++ STL set容器 insert后的set是从小到大排序的。 set.begin() < .. < set.rbegin() 参考代码: 1 class Solution { 2 public: 3 int thirdMax(vector<int>& nums) { 4 set<int> M
阅读全文