04 2021 档案
摘要:问题: 给定一组event的举办起始日表, 可以参加任意event在任意天。 求最多能参加多少个event。 ⚠️ 注意:同一天只能参加一个event。 Example 1: Input: events = [[1,2],[2,3],[3,4]] Output: 3 Explanation: You
阅读全文
摘要:问题: 无限横坐标中,下落正方块问题。 position[i]={x, len} 表示:每次落在坐标 x 的位置,正方块变长len。 求每次落下后,当前最高y坐标的高度。 Example 1: Input: [[1, 2], [2, 3], [6, 1]] Output: [2, 5, 5] Exp
阅读全文
摘要:类似问题:232. Implement Queue using Stacks 问题: 设计数据结构,使用queue实现stack。 实现以下功能: void push(int x) Pushes element x to the top of the stack. int pop() Removes
阅读全文
摘要:问题: 设计数据结构,使用stack实现queue。 实现以下功能: void push(int x) Pushes element x to the back of the queue. int pop() Removes the element from the front of the que
阅读全文
摘要:问题: 给定二维数组, 求其中子矩形中元素和不大于K 的最大和。 Example 1: Input: matrix = [[1,0,1],[0,-2,3]], k = 2 Output: 2 Explanation: Because the sum of the blue rectangle [[0
阅读全文
摘要:相关问题:496. Next Greater Element I 问题: 给定一个数组,和一个大小为k的滑动窗口, 求窗口范围内的最大值依次是多少。 Example 1: Input: nums = [1,3,-1,-3,5,3,6,7], k = 3 Output: [3,3,5,5,6,7] E
阅读全文
摘要:相关问题:496. Next Greater Element I 问题: 给定按照日期推移的每日温度列表。 求每一天,距离下一个更暖和的日子还需要的天数。 For example, given the list of temperatures T = [73, 74, 75, 71, 69, 72,
阅读全文
摘要:相关问题:496. Next Greater Element I 问题: 给定数组num,对于每个元素求下一个更大的元素。 下一个的定义:右边 且 若到末尾元素,循环从index=0开始继续向右。 Example 1: Input: nums = [1,2,1] Output: [2,-1,2] E
阅读全文
摘要:问题: 给定数组num2, 求num1中各数右边第一个大于它的数。 Example 1: Input: nums1 = [4,1,2], nums2 = [1,3,4,2] Output: [-1,3,-1] Explanation: For number 4 in the first array,
阅读全文
摘要:问题: 给定一组数,求其中最大子set,使得set中其中任意两元素之间: a%b=0 or b%a=0 Example 1: Input: nums = [1,2,3] Output: [1,2] Explanation: [1,3] is also accepted. Example 2: Inp
阅读全文
摘要:问题: 设计数据结构,使得完成以下功能: 关注用户: void follow(int followerId, int followeeId) 取关用户: void unfollow(int followerId, int followeeId) 某用户发状态: void postTweet(int
阅读全文
摘要:问题: 设计结构体,能够满足以下两个功能: 向结构体中插入数据 void addNum(int num) 去当前结构体中的中位数 double findMedian() 若共有奇数个数,取最中间的数 若共有偶数个数,取中间两个数之和/2 Example 1: Input ["MedianFinder
阅读全文
摘要:相关问题:146. LRU Cache 问题: 设计类LFUCache,实现LFU Cache Least Frequently Used 优先度为:访问频率最多优先 的缓存。 缓存大小一定,capacity get(key):通过key查找value,若缓存中不存在key,返回-1 put(key
阅读全文
摘要:问题: 设计类LRUCache,实现LRU Cache Least Recently Used 优先度为:最近使用优先 的缓存。 缓存大小一定,capacity get(key):通过key查找value,若缓存中不存在key,返回-1 put(key, value):插入缓存key=value。
阅读全文
摘要:问题: 将给定正整数n,拆成多个数。(使得这些数之和=n) 这些数之积最大是多少。 Example 1: Input: n = 2 Output: 1 Explanation: 2 = 1 + 1, 1 × 1 = 1. Example 2: Input: n = 10 Output: 36 Exp
阅读全文
摘要:问题: 给定多个字符串定义:某个小写字母==(!=)另一个小写字母 求这些定义中,有互相矛盾的情况吗? 有矛盾,返回false,否则返回true。 Example 1: Input: ["a==b","b!=a"] Output: false Explanation: If we assign sa
阅读全文
摘要:问题: 给定一个字符串,表示一个由+-*三种运算符组成的算式。 求给运算式任意加括号,使得计算优先顺序变化。 所得所有结果的可能。 Example 1: Input: expression = "2-1-1" Output: [0,2] Explanation: ((2-1)-1) = 0 (2-(
阅读全文
摘要:问题: 求数组中第k大的元素。 Example 1: Input: nums = [3,2,1,5,6,4], k = 2 Output: 5 Example 2: Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 Output: 4 Constraints: 1 <
阅读全文
摘要:问题: 给定两个int数组,代表两个数位数值的列表。 从两个数组中,按照已有的顺序选取数位数值, 组成一个新的数,长度为k 求能构成的数最大为? Example 1: Input: nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5 Output: [9,
阅读全文
摘要:问题: 给定n个初始状态为off的灯, 第1次,按 1*i 号灯的开关。 第2次,按 2*i 号灯的开关。 ... 第n次,按 n 号灯的开关。 求最后on的灯共有几个。 Example 1: Input: n = 3 Output: 1 Explanation: At first, the thr
阅读全文
摘要:问题: 给n个石子,由你开始选取,和你的朋友轮流进行。 每次选取,可以选取1~3个石子, 最后一个取完石子的人获胜,返回你是否能赢得胜利。 Example 1: Input: n = 4 Output: false Explanation: These are the possible outcom
阅读全文
摘要:问题: 求0~num 每个数的二进制中含有 1 的个数。 Example 1: Input: num = 2 Output: [0,1,1] Explanation: 0 --> 0 1 --> 1 2 --> 10 Example 2: Input: num = 5 Output: [0,1,1,
阅读全文
摘要:问题: 去除有序链表中重复的节点。 Example 1: Input: head = [1,1,2] Output: [1,2] Example 2: Input: head = [1,1,2,3,3] Output: [1,2,3] Constraints: The number of nodes
阅读全文
摘要:问题: 将数组中的0移到末尾。 Example 1: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Example 2: Input: nums = [0] Output: [0] Constraints: 1 <= nums.length <= 1
阅读全文
摘要:问题: 删除数组中的元素val。 返回剩下数组的size。 Example 1: Input: nums = [3,2,2,3], val = 3 Output: 2, nums = [2,2] Explanation: Your function should return length = 2,
阅读全文
摘要:问题: 去除有序数组中重复的数字。 Example 1: Input: nums = [1,1,2] Output: 2, nums = [1,2] Explanation: Your function should return length = 2, with the first two ele
阅读全文
摘要:问题: 给定一个二维数组, 求给定区间围成矩形的和。 Example 1: Input ["NumMatrix", "sumRegion", "sumRegion", "sumRegion"] [[[[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5],
阅读全文
摘要:类似问题: 382. Linked List Random Node 问题: 给定一组数(可能有重复的数字), 求随机取得数字=target的index。 ⚠️ 注意:取得每个数的概率要相同。 Example 1: Input ["Solution", "pick", "pick", "pick"]
阅读全文
摘要:问题: 给定一个链表,求随机抽取一个元素。 使得每个元素被取出的概率相同。 Example 1: Input ["Solution", "getRandom", "getRandom", "getRandom", "getRandom", "getRandom"] [[[1, 2, 3]], [],
阅读全文
摘要:类似解法问题(index符号标记法) 442. Find All Duplicates in an Array 448. Find All Numbers Disappeared in an Array 问题: 给定size=n的数组,记录1~n。 其中存在某个数字重复,占用另一个数字的空间,导致漏
阅读全文
摘要:问题: 勇士救公主问题。 勇士从左上角[0,0]出发,要到达右下角[n-1,m-1]公主所在。 只能向右or向下移动。 格子上的数字代表:加减血。 若到达某个格子勇士血量<1那么,勇士立即死亡。游戏失败。 求,至少在出发时,勇士的初始血量是多少。 Example 1: Input: dungeon
阅读全文
摘要:问题: 求第n个ugly number 定义:ugly number:只由2or3or5作为因数求得。 1为第一个ugly number。 Example 1: Input: n = 10 Output: 12 Explanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12
阅读全文
摘要:问题: 给定字符串s,匹配串t 求s中匹配t的方法有多少种。 匹配:s中存在t的序列。 Example 1: Input: s = "rabbbit", t = "rabbit" Output: 3 Explanation: As shown below, there are 3 ways you
阅读全文
摘要:问题: 求a^b%base的值。 a为int型数 b为int数组,例如[1,2,3,4]代表:b=1234 base=1337。 Example 1: Input: a = 2, b = [3] Output: 8 Example 2: Input: a = 2, b = [1,0] Output:
阅读全文