04 2020 档案

摘要:问题: 橘子催熟问题,0:空地,1:新鲜橘子,2:成熟橘子 每一分钟成熟橘子会催熟四周的新鲜橘子,但如果新鲜橘子四周空着,则不会被催熟。 求给定数组情况,最多需要多久催熟所有的橘子,如果无法催熟所有则返回-1。 Example 1: Input: [[2,1,1],[1,1,0],[0,1,1]] 阅读全文
posted @ 2020-04-29 19:10 habibah_chang 编辑
摘要:问题: 给定数组0代表海水,1代表陆地,若陆地上下左右皆为海水,那么则称该陆地为一小岛。 求给定数组中有多少小岛。 Example 1: Input: 11110 11010 11000 00000 Output: 1 Example 2: Input: 11000 11000 00100 0001 阅读全文
posted @ 2020-04-29 15:53 habibah_chang 编辑
摘要:问题: 买股票问题,给出一个数组,表示某个股票在每一天的价格, 买家可以在一天买入,在之后的一天卖出,一次交易会产生交易费fee,求最大获利。 Example 1: Input: prices = [1, 3, 2, 8, 4, 9], fee = 2 Output: 8 Explanation: 阅读全文
posted @ 2020-04-26 15:31 habibah_chang 编辑
摘要:问题: 求给定数组的连续子数组个数,使得子数组之乘积,小于给定值 k Example 1: Input: nums = [10, 5, 2, 6], k = 100 Output: 8 Explanation: The 8 subarrays that have product less than 阅读全文
posted @ 2020-04-24 18:29 habibah_chang 编辑
摘要:问题: 给定一个非负整数,求只交换一次某两位的数字,使得值最大,求该最大值。 Example 1: Input: 2736 Output: 7236 Explanation: Swap the number 2 and the number 7. Example 2: Input: 9973 Out 阅读全文
posted @ 2020-04-21 14:24 habibah_chang 编辑
摘要:问题: 给定StartWord和EndWord,在给定的dict中寻找每次值变换一个字母,最终从StartWord能够推移到EndWord的所有最短序列。 Example 1: Input: beginWord = "hit", endWord = "cog", wordList = ["hot", 阅读全文
posted @ 2020-04-21 13:11 habibah_chang 编辑
摘要:问题: 给定一个由0,1 组成的二维数组,0代表海水,1代表陆地, 求给定数组所形成小岛的最大面积。 Example 1: [[0,0,1,0,0,0,0,1,0,0,0,0,0], [0,0,0,0,0,0,0,1,1,1,0,0,0], [0,1,1,0,1,0,0,0,0,0,0,0,0], 阅读全文
posted @ 2020-04-20 14:04 habibah_chang 编辑
摘要:问题: 给定一个数组,求从中取得3组连续长度为 k 的子数组,使得3组数组和为最大,且使得3组的index尽可能小(★)。 Example: Input: [1,2,1,2,6,7,5,1], 2 Output: [0, 3, 5] Explanation: Subarrays [1, 2], [ 阅读全文
posted @ 2020-04-20 12:51 habibah_chang 编辑
摘要:问题: 给定一个n,有数组1~n, 排列该数组,使得数组两两元素之间的差值有k种。 Example 1: Input: n = 3, k = 1 Output: [1, 2, 3] Explanation: The [1, 2, 3] has three different positive int 阅读全文
posted @ 2020-04-19 13:28 habibah_chang 编辑
摘要:问题: 给定一个攻击时间点数组,和每一次攻击所持续的时间长度。 求在攻击时间点数组的攻击下,一共能持续多久。 Example 1: Input: [1,4], 2 Output: 4 Explanation: At time point 1, Teemo starts attacking Ashe 阅读全文
posted @ 2020-04-19 11:26 habibah_chang 编辑
摘要:问题: 给定数组,nums[i]=k,k!=0 若k>0, 则下一个数的index是向右+|k| 若k<0,则下一个数的index是向左-|k| (数组首尾相连) 这样的移动规则,问是否存在形成一个循环圈的访问环。(该环长度>1,且单向移动) 解法: 快慢指针法 慢指针一次移动一个,快指针一次移动两 阅读全文
posted @ 2020-04-16 16:07 habibah_chang 编辑
摘要:问题: 给定一个数组,1 ≤ a[i] ≤ n (n = size of array),其中一些元素出现2次,其他出现1次, 求 出现两次的这些元素。 要求:不借助额外空间,时间复杂度为O(n) 解法: 抓住该题目给定数组的特性: ·所有元素 在1~n之间,可联系到 数值 和 偏移位置 的对应关系。 阅读全文
posted @ 2020-04-16 10:34 habibah_chang 编辑
摘要:问题: 设计数据结构,使得以下三个方法的时间复杂度都为O(1) 允许插入重复数字。 insert(val): Inserts an item val to the collection. remove(val): Removes an item val from the collection if 阅读全文
posted @ 2020-04-14 19:42 habibah_chang 编辑
摘要:问题: 设计数据结构,使得以下三个方法的时间复杂度都为O(1) insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item val from the set if p 阅读全文
posted @ 2020-04-14 13:33 habibah_chang 编辑
摘要:问题: 给定数组(含有正数负数),求连续子集合和=k的子集合数。 Example 1: Input:nums = [1,1,1], k = 2 Output: 2 Note: The length of the array is in range [1, 20,000]. The range of 阅读全文
posted @ 2020-04-12 19:30 habibah_chang 编辑
摘要:问题: 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 编辑

点击右上角即可分享
微信分享提示