随笔分类 -  leetcode

摘要:问题: degree:给定数组中重复最多元素的次数 求重复次数为degree的元素中,距离最短子数组的长度。 Example 1: Input: [1, 2, 2, 3, 1] Output: 2 Explanation: The input array has a degree of 2 beca 阅读全文
posted @ 2020-04-12 17:26 habibah_chang
摘要:问题: 给定字符串,返回连续相同字符子串长度>=3的始终位置集合。 Example 1: Input: "abbxxxxzzy" Output: [[3,6]] Explanation: "xxxx" is the single large group with starting 3 and end 阅读全文
posted @ 2020-04-11 11:30 habibah_chang
摘要:问题: 给定一个矩阵,1代表活,0代表死,进行下列转化,求所得矩阵 1.对于一个活节点,若周围8个cell,有小于2个活着,那么变死节点 2.对于一个活节点,若周围8个cell,有2或3个活着,那么保持活节点 3.对于一个活节点,若周围8个cell,有大于3个活着,那么变死节点 4.对于一个死节点, 阅读全文
posted @ 2020-04-11 11:02 habibah_chang
摘要:问题: 给定一个包含n + 1个整数的数组,其中每一个整数均介于[1, n]之间,求重复的数字。 Example 1: Input: [1,3,4,2,2] Output: 2 Example 2: Input: [3,1,3,4,2] Output: 3 Note: You must not mo 阅读全文
posted @ 2020-04-05 14:14 habibah_chang
摘要:问题: 给定数组,求除本位数字以外所有数字之乘积的新数组 Example: Input: [1,2,3,4] Output: [24,12,8,6] Constraint: It's guaranteed that the product of the elements of any prefix 阅读全文
posted @ 2020-04-05 13:09 habibah_chang
摘要:同样思想的升级版【https://www.cnblogs.com/habibah-chang/p/12743884.html】 问题: 给定StartWord和EndWord,在给定的dict中寻找每次值变换一个字母,最终从StartWord能够推移到EndWord的一个序列步数。 Note: Re 阅读全文
posted @ 2020-04-05 11:38 habibah_chang
摘要:问题: 求给定数组中,最长连续递增子数组 Example 1: Input: [1,3,5,4,7] Output: 3 Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3. E 阅读全文
posted @ 2020-04-04 17:26 habibah_chang
摘要:问题: 给定任务数组,每个任务用一个大写字母表示。 给定相同任务之间的缓冲间隔 n(间隔中可填充其他任务,若没有则使之空闲 idle ) 求对给定任务一览进行安排,使得所用时间最少,求此时间。 Example: Input: tasks = ["A","A","A","B","B","B"], n 阅读全文
posted @ 2020-04-04 17:07 habibah_chang
摘要:问题: 求给定数组中,每三个值作为三角形三边,可构成三角形的集合个数。 Example 1: Input: [2,2,3,4] Output: 3 Explanation: Valid combinations are: 2,3,4 (using the first 2) 2,3,4 (using 阅读全文
posted @ 2020-04-04 11:55 habibah_chang
摘要:问题:求是否给定的数列为一个山形数列(先单调增,再单调减) 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 阅读全文
posted @ 2020-03-29 16:15 habibah_chang
摘要:问题: 求一个数列中的,最大嵌套子数列长度 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] = 阅读全文
posted @ 2020-03-29 15:37 habibah_chang
摘要:问题: 求未排序数列中,最长连续数列长度。 Example: Input: [100, 4, 200, 1, 3, 2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefo 阅读全文
posted @ 2020-03-29 14:50 habibah_chang
摘要:问题:求一个数列中,出现次数>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,则可能出现最多两个结果。 将两个待选结果设 阅读全文
posted @ 2020-03-21 14:00 habibah_chang
摘要:问题:求给定数列中,最短子数列,使子数列之和>=给定值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 阅读全文
posted @ 2020-03-21 13:34 habibah_chang
摘要:问题:求数组的任意峰值。两侧都从-∞开始向上递增。 Example 1: Input: nums = [1,2,3,1] Output: 2 Explanation: 3 is a peak element and your function should return the index numb 阅读全文
posted @ 2020-03-21 13:27 habibah_chang
摘要:同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 方法: 思想 阅读全文
posted @ 2020-03-21 13:20 habibah_chang
摘要:问题:求被旋转了的排序数列中的最小值。 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的中间值 阅读全文
posted @ 2020-03-21 13:11 habibah_chang
摘要:问题: 给出给定数组的描述: 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 阅读全文
posted @ 2020-03-15 14:41 habibah_chang
摘要:问题:给定数组中,能否最多修改一个数,使得数组成为非减数组,即对数组中任意相邻两数:nums[i] <= nums[i+1] Example 1: Input: [4,2,3] Output: True Explanation: You could modify the first 4 to 1 t 阅读全文
posted @ 2020-03-15 14:09 habibah_chang
摘要:问题: 处理给定数组,(平滑处理)使得每个元素=周围+自己共9个元素的平均值。(若没有9个元素,则是周围一圈+自己元素的平均值) Input: [[1,1,1], [1,0,1], [1,1,1]] Output: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] Explanat 阅读全文
posted @ 2020-03-15 13:38 habibah_chang