随笔分类 - leetcode
摘要:问题: 设计类: 给定N个座位。 入座:seat:给当前进入的考生,安排最远距离座位,返回座位号。 离开:leave(p):座位号为p的考生离开考场,该座位空出来。 Example 1: Input: ["ExamRoom","seat","seat","seat","seat","leave","
阅读全文
摘要:参考:C++ 中自定义比较器的正确姿势 function: sort 1,2,3,4,5 (default: std::less<int>(), "<" ) print顺序:1->2,3,4,5(按照内存从小到大地址) cmp使用方法:比较方法 or 比较器对象 :std::greater<int>
阅读全文
摘要:问题: 给定多个小矩形,rec[i]={x1,y1,x2,y2} (x1, y1) 代表小矩形的↙️左下顶点坐标 (x2, y2) 代表小矩形的↗️右上顶点坐标 这些小矩形是否能组成一个完美矩形。 要求:不能存在重叠or空余的内部空间。 Example 1: Input: rectangles =
阅读全文
摘要:问题: 求给定 字符串s 是否为 字符串t 的子序列。 Example 1: Input: s = "abc", t = "ahbgdc" Output: true Example 2: Input: s = "axc", t = "ahbgdc" Output: false Constraints
阅读全文
摘要:问题: 给定x坐标,上每一个点代表陆地的高度。 求从0~最大坐标之间,累积雨水,最多能储蓄多少水量。 Example 1: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: The above elevation map
阅读全文
摘要:问题: 给定算数字符串,求解。 其中字符串包含: 数字: '0'~'9':可构成任意n位数十进制数。 运算符号: '-':减法 '+':加法 '*':乘法(优先级高) '/':除法(优先级高) 括号: '(':优先计算括号内 ')':优先计算括号内 空格: ' ':无意义 Example 1: In
阅读全文
摘要:问题: 给定一组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。
阅读全文