Meta 高频面试题
Top 100 in 2022 Feb
1249. Minimum Remove to Make Valid Parentheses Stack or Two-way scan
680. Valid Palindrome II Recursive follow up是可以remove at most k
560. Subarray Sum Equals K hashMap, initial data
528. Random Pick with Weight 又是一道pre-sum题, 数组为空,所有数字都是0
973. K Closest Points to Origin PriorityQueue or QuickSelect
426. 将二叉搜索树转化为排序的双向链表 中序遍历 or morris遍历
215. Kth Largest Element in an Array QuickSelect
50. Pow(x, n) 递归 Warning StackOverflow
827. Making A Large Island Union Find Set with details
31. Next Permutation 三步走:1. locate; 2. switch; 3. reorder
347. Top K Frequent Elements QuickSelect
721. Accounts Merge 组编号,常规UFS,三次遍历
543. Diameter of Binary Tree 全局变量 or int[]
523. Continuous Subarray Sum Map,要注意初始化和变体
301. Remove Invalid Parentheses dfs, backtracking
249. 移位字符串分组 hash的方法:(s.charAt(i) - s.charAt(i - 1) + 26) % 26
138. Copy List with Random Pointer 循环 or 迭代
162. Find Peak Element linear scan / binary search
56. Merge Intervals 1. sort; 2. listing; 3. to array
282. Expression Add Operators backtrack 高级回溯 要用long 避免溢出
125. Valid Palindrome Character.isLetterOrDigit, toLowerCase
346. 数据流中的移动平均值 1. Queue; 2. 环形列表存储
953. Verifying an Alien Dictionary Special sort or compare bwt i-1 and i
42. Trapping Rain Water 双指针 or 两次遍历
133. Clone Graph DFS
266. Palindrome Permutation set / count
23. Merge k Sorted Lists PriorityQueue or Divide and Concur for (i = 0; i < n - interval; i += (2*interval)) interval *= 2; 注意数组长度为0的情况
2060. Check if an Original String Exists Given Two Encoded Strings
1539. Kth Missing Positive Number 两种方法:1. 遍历; 2. Binary Search
269. 火星词典 拓扑排序 Topological Sort - 1. order; 2. queue; 3. toString
273. Integer to English Words Recursive
1
2
3private final String[] LESS_THAN_20 = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
private final String[] TENS = {"", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
private final String[] THOUSANDS = {"", "Thousand", "Million", "Billion"};398. Random Pick Index Reservoir sampling
658. Find K Closest Elements Binary Search
253. 会议室 II PriorityQueue or Two pointers 双指针要再练一下
1944. Number of Visible People in a Queue 从左往右 / 从右往左都可以
270. 最接近的二叉搜索树值 磕磕绊绊
647. Palindromic Substrings 中心扩展 O(n^2)
16. 3Sum Closest 去重复
958. Check Completeness of a Binary Tree DFS (complete tree: 2^k +1 ⇒ x & (x + 1) == 0) / BFS
739. Daily Temperatures 单调栈 / array
778. Swim in Rising Water PriorityQueue + DFS / UnionFind / Binary Search 复杂度都差不多
76. Minimum Window Substring 双指针要再练一下 特别小心字符串没有匹配的地方
Top Questions in LeetCode
- 括号系列
- 1249. Minimum Remove to Make Valid Parentheses Stack or Two-way scan
- 301. Remove Invalid Parentheses dfs, backtracking
- 921. Minimum Add to Make Parentheses Valid One pass
- 1541. Minimum Insertions to Balance a Parentheses String
- 20. Valid Parentheses Stack
- 32. Longest Valid Parentheses dp
- 22. Generate Parentheses dfs
- 1003. Check If Word Is Valid After Substitutions Stack
- 1963. Minimum Number of Swaps to Make the String Balanced
- 2116. Check if a Parentheses String Can Be Valid
- 953. Verifying an Alien Dictionary Special sort or compare bwt i-1 and i
- 回文
- 125. Valid Palindrome Character.isLetterOrDigit, toLowerCase
- 680. Valid Palindrome II Recursive follow up是可以remove at most k
- 973. K Closest Points to Origin PriorityQueue or QuickSelect
- 273. Integer to English Words Recursive
- 数学
- 简单加法
- 求和
- Map
- 15. 3Sum
- 560. Subarray Sum Equals K hashMap, initial data
- 523. Continuous Subarray Sum Map,要注意初始化和变体
- 1. Two Sum
- 1570. 两个稀疏向量的点积
- 16. 3Sum Closest
- Sum妙用
- 528. Random Pick with Weight 又是一道pre-sum题
- Map
- 乘法
- 238. 除自身以外数组的乘积 - Two-way scan, 进化one-way
- 高级数学
- 29. Divide Two Integers 位运算真不行
- 43. Multiply Strings 小心0
- 282. Expression Add Operators backtrack 高级回溯
- 65. Valid Number
- 227. Basic Calculator II
- 排列组合
- 31. Next Permutation 三步走:1. locate; 2. switch; 3. reorder
- 297. 二叉树的序列化与反序列化
- 10. Regular Expression Matching
- intervals
- 56. Merge Intervals 1. sort; 2. listing; 3. to array
- 986. Interval List Intersections
- 252. 会议室
- 253. 会议室 II PriorityQueue or Two pointers 双指针要再练一下
- 636. Exclusive Time of Functions
- 621. Task Scheduler 计算细节
- 215. Kth Largest Element in an Array QuickSelect
- 283. Move Zeroes
- TreeOrder DFS or BFS
- 938. Range Sum of BST
- 314. 二叉树的垂直遍历
- 173. Binary Search Tree Iterator Stack
- 987. Vertical Order Traversal of a Binary Tree Sort
- 103. Binary Tree Zigzag Level Order Traversal
- 107. Binary Tree Level Order Traversal II
- 111. Minimum Depth of Binary Tree
- 637. Average of Levels in Binary Tree
- 429. N-ary Tree Level Order Traversal
- 993. Cousins in Binary Tree
- 545. 二叉树的边界
- 543. Diameter of Binary Tree 全局变量 or int[]
- 124. Binary Tree Maximum Path Sum
- 199. Binary Tree Right Side View BFS
- 133. Clone Graph DFS
- 138. Copy List with Random Pointer 循环 or 迭代
- 91. Decode Ways DP
- 88. Merge Sorted Array
- 23. Merge k Sorted Lists PriorityQueue or Divide and Concur for (i = 0; i < n - interval; i += (2*interval)) interval *= 2;
- 50. Pow(x, n) 递归 Warning StackOverflow
- 76. Minimum Window Substring 双指针要再练一下
- 200. Number of Islands DFS 颜色标记法 or UnionFindSet
- 269. 火星词典 拓扑排序 Topological Sort - 1. order; 2. queue; 3. toString
- 426. 将二叉搜索树转化为排序的双向链表 中序遍历 or morris遍历
- 211. Design Add and Search Words Data Structure Trie
- 1428. 至少有一个 1 的最左端列 二分法
- 求祖宗系列
- 278. First Bad Version 简单二分
- 42. Trapping Rain Water 双指针 or 两次遍历
- 139. Word Break dp
- 17. Letter Combinations of a Phone Number backtrack
- 721. Accounts Merge 注意union find的思路和优化
- 1762. 能看到海景的建筑物
- 146. LRU Cache 细节
- 121. Best Time to Buy and Sell Stock
- 98. Validate Binary Search Tree 中序遍历 / 递归
- 347. Top K Frequent Elements QuickSelect
- 438. Find All Anagrams in a String
- 162. Find Peak Element
- 34. Find First and Last Position of Element in Sorted Array
- 33. Search in Rotated Sorted Array
- 140. Word Break II
- 670. Maximum Swap
- 339. 嵌套列表权重和
- 785. Is Graph Bipartite? 颜色标记法
- 8. String to Integer (atoi) 分情况讨论,疯狂if else orDeterministic Finite Automaton (DFA) 注意溢出情况
- 114. Flatten Binary Tree to Linked List
- 311. 稀疏矩阵的乘法
- 349. Intersection of Two Arrays set or 排序后的双指针
- 159. 至多包含两个不同字符的最长子串
- 340. 至多包含 K 个不同字符的最长子串
- 257. Binary Tree Paths
- 4. Median of Two Sorted Arrays
- 157. 用 Read4 读取 N 个字符
- 进阶版
- 127. Word Ladder
- 13. Roman to Integer
- 3. Longest Substring Without Repeating Characters
- 270. 最接近的二叉搜索树值 这么简单的一道题,为啥我没做出来??
- 317. 离建筑物最近的距离
- 249. 移位字符串分组 hash的方法:(s.charAt(i) - s.charAt(i - 1) + 26) % 26
- 304. Range Sum Query 2D - Immutable
- 896. Monotonic Array
- 398. Random Pick Index Reservoir sampling
- 380. Insert Delete GetRandom O(1) List + Map
- 286. 墙与门
- 977. Squares of a Sorted Array
- 5. Longest Palindromic Substring
- 708. 循环有序列表的插入
- 325. 和等于 k 的最长子数组长度
- 377. Combination Sum IV DP
- 791. Custom Sort String
- 498. Diagonal Traverse
- 378. Kth Smallest Element in a Sorted Matrix
- 341. Flatten Nested List Iterator
- 36. Valid Sudoku (n n)
- 346. 数据流中的移动平均值 1. Queue; 2. 环形列表存储
- 1047. Remove All Adjacent Duplicates In String
- 1209. Remove All Adjacent Duplicates in String II
- 529. Minesweeper
- 298. 二叉树最长连续序列
- 549. 二叉树中最长的连续序列 follow up
- 24. Swap Nodes in Pairs Recursion → Iteration
- 719. Find K-th Smallest Pair Distance 精准二分
- 28. Implement strStr() KMP 太难了
- 1382. Balance a Binary Search Tree
- 480. Sliding Window Median
- 151. Reverse Words in a String
- 71. Simplify Path 用Deque
stack = new LinkedList<>();,可以两头操作 - 772. 基本计算器 III 只有加和乘,follow up是加上减和除
- 1539. Kth Missing Positive Number Binary Search
- 983. Minimum Cost For Tickets dp
- 658. Find K Closest Elements Binary Search
- 408. 有效单词缩写
- 489. 扫地机器人
- 268. Missing Number XOR; Sum; Binary Search
- 366. 寻找二叉树的叶子节点
- 295. Find Median from Data Stream
- 中心对称数
- 207. Course Schedule Topological Sorting
- 827. Making A Large Island Union Find Set with details
- 112. Path Sum recursion or iteration
- 跳跃游戏
- 55. Jump Game Greedy
- 45. Jump Game II Greedy
- 1306. Jump Game III recursion or iteration
- 1345. Jump Game IV Queue
- 1340. Jump Game V
- 1696. Jump Game VI Deque or in-place dp
- 1871. Jump Game VII Smart DP
- 14. Longest Common Prefix Horizontal scanning; Vertical scanning; Divide and conquer; Binary search
- 739. Daily Temperatures
- bitmask
- 129. Sum Root to Leaf Numbers
- 323. 无向图中连通分量的数目 UnionFindSet
- 939. Minimum Area Rectangle
- 963. Minimum Area Rectangle II
- 79. Word Search
- 702. 搜索长度未知的有序数组
- 277. 搜寻名人
- 1004. Max Consecutive Ones III
- 424. Longest Repeating Character Replacement
- 1091. Shortest Path in Binary Matrix
- 1011. Capacity To Ship Packages Within D Days
- 622. Design Circular Queue
- 863. All Nodes Distance K in Binary Tree
- 766. Toeplitz Matrix
- 1891. Cutting Ribbons
- 270. Closest Binary Search Tree Value
- 515. Find Largest Value in Each Tree Row
- 695. Max Area of Island
- 116. Populating Next Right Pointers in Each Node
- 266. Palindrome Permutation