smilelc3 / leetcode

Leetcode Solution C/C++/Golang Version(leetocde 刷题解答,C、C++、Golang 版本 )
GNU General Public License v3.0
3 stars 2 forks source link
c cpp golang leetcode sql

leetcode自由刷题

说明

C 补充

C++ 补充

Golang 补充

Python 补充

SQL 补充

Shell补充

汇总表

编号 题目 代码文件 时间复杂度 简述 空间复杂度
1 Two Sum two-sum.go O(n) 哈希Map
2 Add Two Numbers add-two-numbers.go O(n) 单向链表
3 Longest Substring Without Repeating Characters longest-substring-without-repeating-characters.go O(n) DP优化
4 Median of Two Sorted Arrays median-of-two-sorted-arrays.go O(log(min(m,n))) 参考Grandyang博客
5 Longest Palindromic Substring longest-palindromic-substring.go O(n) manacher算法
6 ZigZag Conversion zigzag-conversion.go O(n) 规律总结
7 Reverse Integer reverse-integer.go O(n) strconv.Itoa()+strconv.Atoi()实现
8 String to Integer (atoi) string-to-integer-atoi.go 正则匹配
9 Palindrome Number palindrome-number.go O(n/2) strconv.Itoa()实现
10 Regular Expression Matching regular-expression-matching.go O(n*m) DP
11 Container With Most Water container-with-most-water.go O(n) two-pointer算法
12 Integer to Roman integer-to-roman.go O(n) 打表
13 Roman to Integer roman-to-integer.go O(n) switch-case
14 Longest Common Prefix longest-common-prefix.go O(n*m) if模拟
15 3Sum 3sum.go O(n^2) two-pointer
16 3Sum Closest 3sum-closest.go O(n^2) two-pointer
17 Letter Combinations of a Phone Number letter-combinations-of-a-phone-number.go O(4^n) 循环
18 4Sum 4sum.go O(n^3) two-pointer
19 Remove Nth Node From End of List remove-nth-node-from-end-of-list.go O(n) 循环数组(one pass)
20 Valid Parentheses valid-parentheses.go O(n)
21 Merge Two Sorted Lists merge-two-sorted-lists.go O(m+n) 递归
22 Generate Parentheses generate-parentheses.go O(2^n) 递归
23 Merge k Sorted Lists merge-k-sorted-lists.go O(log(n)*m) 分治
24 Swap Nodes in Pairs swap-nodes-in-pairs.go O(n) 单链表交换节点
25 Reverse Nodes in k-Group reverse-nodes-in-k-group.go O(n) 记录前驱+后驱节点 O(1)
26 Remove Duplicates from Sorted Array remove-duplicates-from-sorted-array.go O(n) slice传参:带地址的结构体值 O(1)
27 Remove Element remove-element.go O(n) 单链表删除操作 O(1)
28 Implement strStr() implement-strstr.go O(n+m) KMP算法
29 Divide Two Integers divide-two-integers.go O(log(n)) 位操作实现除法
30 Substring with Concatenation of All Words substring-with-concatenation-of-all-words.go O(n) 滑动窗口+HashMap
31 Next Permutation next-permutation_test.go O(n) 参考C++ std::next_next_permutation O(1)
32 Longest Valid Parentheses longest-valid-parentheses.go O(n)
33 Search in Rotated Sorted Array search-in-rotated-sorted-array.go O(log(n)) 二分查找
34 Find First and Last Position of Element in Sorted Array find-first-and-last-position-of-element-in-sorted-array.go O(log(n)) 二分查找
35 Search Insert Position search-insert-position.go O(log(n)) 二分查找
36 Valid Sudoku valid-sudoku.go O(n^2) 位操作判重
37 Sudoku Solver sudoku-solver.go DanceLink X算法
38 Count and Say count-and-say.go 递归 + strings.Builder加速
39 Combination Sum combination-sum.go DFS
40 Combination Sum II combination-sum-ii.go DFS+剪枝
41 First Missing Positive first-missing-positive.go O(n) 判 nums[idx]=nums[nums[idx]-1] O(1)
42 Trapping Rain Water trapping-rain-water.go O(n) 不下降子数组
43 Multiply Strings multiply-strings.go O(n+m) 模拟乘法
44 Wildcard Matching wildcard-matching.go O(n) 双指针
45 Jump Game II jump-game-ii.go O(n) 二次扩展 O(1)
46 Permutations permutations.go O(n!) 全排列
47 Permutations II permutations-ii.go 不重复全排列
48 Rotate Image rotate-image.go O(n^2) 图像处理:旋转变换矩阵 O(1)
49 Group Anagrams group-anagrams.go O(m*n) HashMap+桶排序思想
50 Pow(x, n) powx-n.go O(log(n)) 快速幂
51 N-Queens n-queens.go O(n^n) 回溯+位操作加速
52 N-Queens II n-queens-ii.go O(1) 打表 O(1)
53 Maximum Subarray maximum-subarray.go O(n) 最大和子串 O(1)
54 Spiral Matrix spiral-matrix.go O(m*n) 模拟
55 Jump Game jump-game.go O(n) 二次扩展 O(1)
56 Merge Intervals merge-intervals.go O(nlog(n)) slice排序
57 Insert Interval insert-interval.go O(n) 模拟
58 Length of Last Word length-of-last-word.go O(n) 找首次非后导空格符
59 Spiral Matrix II spiral-matrix-ii.go O(n^2) 模拟
60 Permutation Sequence permutation-sequence.go O(n) 规律+递归
61 Rotate List rotate-list.go O(n) 旋转单链表 O(1)
62 Unique Paths unique-paths.go O(m*n) DP+滚动数组 O(min(m,n))
63 Unique Paths II unique-paths-ii.go O(m*n) DP+滚动数组 O(min(m,n))
64 Minimum Path Sum minimum-path-sum.go O(m*n) DP
65 Valid Number valid-number.go O(n) 确定有限状态自动机DFA O(1)
66 Plus One plus-one.go O(n) 模拟进位
67 Add Binary add-binary.go O(n) 模拟二进制加法
68 Text Justification text-justification.go O(m*n) 格式控制
69 Sqrt(x) sqrtx.go O(log(n)) 二叉搜索树 O(1)
70 Climbing Stairs climbing-stairs.go O(n) 斐波那契数列(递推) O(1)
71 Simplify Path simplify-path.go simplify-path.cpp O(n) O(n)
72 Edit Distance edit-distance.go O(m*n) 编辑距离DP O(m*n)
73 Set Matrix Zeroes set-matrix-zeroes.go O(m*n) 表头标记 O(1)
74 Search a 2D Matrix search-a-2d-matrix.go O(log(m*n)) 二分查找 O(1)
75 Sort Colors sort-colors.go O(n) 桶排序 O(1)
76 Minimum Window Substring minimum-window-substring.go O(n) 滑动窗口+数组代替HashMap优化
77 Combinations combinations.go O((n-k)!) 排列:递归
78 Subsets subsets.go O(2^n) 全子集:递归
79 Word Search word-search.go DFS
80 Remove Duplicates from Sorted Array II remove-duplicates-from-sorted-array-ii.go O(n) 遍历 O(1)
81 Search in Rotated Sorted Array II search-in-rotated-sorted-array-ii.go O(n) 二分搜索
82 Remove Duplicates from Sorted List II remove-duplicates-from-sorted-list-ii.go O(n) 维护单链表preNode
83 Remove Duplicates from Sorted List remove-duplicates-from-sorted-list.go O(n) 保证pNode.Val != pNode.Next.Val
84 Largest Rectangle in Histogram largest-rectangle-in-histogram.go O(n) 单调栈
85 Maximal Rectangle maximal-rectangle.go O(m*n) 转换为直方图求最大矩形:单调栈
86 Partition List partition-list.go O(n) 双指针 O(1)
87 Scramble String scramble-string.go 分治
88 Merge Sorted Array merge-sorted-array.go O(n) 从后向前遍历
89 Gray Code gray-code.go gray-code.cpp O(2^n) 格雷码
90 Subsets II subsets-ii.go O(2^n) 去重全子集:递归
91 Decode Ways decode-ways.go O(n) 斐波那契变形+滚动数组 O(1)
92 Reverse Linked List II reverse-linked-list-ii.go O(n) 单链表部分翻转 O(1)
93 Restore IP Addresses restore-ip-addresses.go DFS
94 Binary Tree Inorder Traversal binary-tree-inorder-traversal.go O(N) 中序遍历(Morris遍历) O(1)
95 Unique Binary Search Trees II unique-binary-search-trees-ii.go 异构二叉搜索树
96 Unique Binary Search Trees unique-binary-search-trees.go O(1) 卡特兰数 O(1)
97 Interleaving String interleaving-string.go O(mn) DP+滚动数组+状态压缩 O(1)
98 Validate Binary Search Tree validate-binary-search-tree.go O(n) 判定二叉搜索树
99 Recover Binary Search Tree recover-binary-search-tree.go O(n) Morris中序遍历 O(1)
100 Same Tree same-tree.go O(n) 树的遍历
101 Symmetric Tree symmetric-tree.go O(n) 相同层子树递归比较 O(n)
102 Binary Tree Level Order Traversal binary-tree-level-order-traversal.go O(n) 二叉树层级遍历 O(log(n))
103 Binary Tree Zigzag Level Order Traversal binary-tree-zigzag-level-order-traversal.go O(n) 二叉树层级遍历 O(log(n))
104 Maximum Depth of Binary Tree maximum-depth-of-binary-tree.go O(n) DFS+BFS O(n)
105 Construct Binary Tree from Preorder and Inorder Traversal construct-binary-tree-from-preorder-and-inorder-traversal.cpp O(n) 先序+中序构造二叉树 O(n)
106 Construct Binary Tree from Inorder and Postorder Traversal construct-binary-tree-from-inorder-and-postorder-traversal.cpp O(n) 中序+后序构造二叉树 O(n)
107 Binary Tree Level Order Traversal II binary-tree-level-order-traversal-ii.cpp O(n) BFS O(n)
108 Convert Sorted Array to Binary Search Tree convert-sorted-array-to-binary-search-tree.cpp O(n) 有序数组转BTS:分治 O(n)
109 Convert Sorted List to Binary Search Tree convert-sorted-list-to-binary-search-tree.cpp O(n) 有序链表转BTS:分治 O(n)
110 Balanced Binary Tree balanced-binary-tree.cpp O(n) 判平衡二叉树:递归
111 Minimum Depth of Binary Tree minimum-depth-of-binary-tree.cpp O(n) 二叉树最小深度:DFS+剪枝
112 Path Sum path-sum.cpp O(n) DFS遍历树 O(1)
113 Path Sum II path-sum-ii.cpp O(n) DFS遍历树+记录路径 O(n)
114 Flatten Binary Tree to Linked List flatten-binary-tree-to-linked-list.cpp O(n) 转换二叉树为先序链表:直接修改树 O(1)
115 Distinct Subsequences distinct-subsequences.cpp O(n^2) DP+滚动数组 O(n)
116 Populating Next Right Pointers in Each Node populating-next-right-pointers-in-each-node.cpp O(n) 二叉树的DFS O(1)
117 Populating Next Right Pointers in Each Node II populating-next-right-pointers-in-each-node-ii.cpp O(n) 二叉树的DFS:根右左 O(1)
118 Pascal's Triangle pascals-triangle.cpp O(n^2) 构建帕斯卡三角 O(n^2)
119 Pascal's Triangle II pascals-triangle-ii.cpp O(n^2) 构建帕斯卡三角单行 O(n)
120 Triangle triangle.cpp O(n^2) DP+滚动数组 O(n)
121 Best Time to Buy and Sell Stock best-time-to-buy-and-sell-stock.cpp O(n) 维护前驱最小 O(1)
122 Best Time to Buy and Sell Stock II best-time-to-buy-and-sell-stock-ii.cpp O(n) 贪心 O(1)
123 Best Time to Buy and Sell Stock III best-time-to-buy-and-sell-stock-iii.cpp O(n) DP O(1)
124 Binary Tree Maximum Path Sum binary-tree-maximum-path-sum.cpp O(n) DFS O(n)
125 Valid Palindrome valid-palindrome.cpp O(n) 判断回文字串 O(1)
126 Word Ladder II word-ladder-ii.cpp O(n*26^(l/2)) 双向BFS+DFS O(k*n)
127 Word Ladder word-ladder.cpp O(n*26^(l/2)) 双向BFS O(n)
128 Longest Consecutive Sequence longest-consecutive-sequence.cpp O(n) HashMap O(n)
129 Sum Root to Leaf Numbers sum-root-to-leaf-numbers.cpp O(2^n) 二叉树深度遍历 O(1)
130 Surrounded Regions longest-consecutive-sequence.cpp O(m*n) DFS地图 O(1)
131 Palindrome Partitioning palindrome-partitioning.cpp O(2^n) DFS+DP O(2^n)
132 Palindrome Partitioning II palindrome-partitioning-ii.cpp O(n^2) DP O(n)
133 Clone Graph clone-graph.cpp O(VE) 深拷贝:无向图 O(VE)
134 Gas Station gas-station.cpp O(n) 贪心 O(1)
135 Candy candy.cpp O(n) 贪心 O(n)
136 Single Number single-number.cpp O(n) 异或判重 O(1)
137 Single Number II single-number-ii.cpp O(n) 位操作模拟三进制 O(1)
138 Copy List with Random Pointer copy-list-with-random-pointer.cpp O(n) 深拷贝:原节点后拷贝新节点 O(1)
139 Word Break word-break.cpp O(n^2) HashMap+DP O(n)
140 Word Break II word-break-ii.cpp DFS+HashSet O(n)
141 Linked List Cycle linked-list-cycle.go linked-list-cycle.cpp O(n) 链表判环:快慢指针 O(1)
142 Linked List Cycle II linked-list-cycle-ii.cpp O(n) 链表环起点:快慢指针 O(1)
143 Reorder List reorder-list.cpp O(n) 链表重排序 O(1)
145 Binary Tree Postorder Traversal binary-tree-postorder-traversal.cpp O(n) 二叉树后序遍历 O(n)
146 LRU Cache lru-cache.cpp O(1) 双向链表+HashMap实现LRU O(n)
147 Insertion Sort List insertion-sort-list.cpp O(n^2) 单链表插入排序 O(1)
148 Sort List sort-list.cpp O(nlog(n)) 单链表归并排序 O(1)
149 Max Points on a Line max-points-on-a-line.cpp O(n^2) 三点枚举优化/斜率HashMap O(n)
150 Evaluate Reverse Polish Notation evaluate-reverse-polish-notation.cpp O(n) 后缀表达式(逆波兰式)求值 O(n)
151 Reverse Words in a String reverse-words-in-a-string.cpp O(n) 单词翻转 O(1)
152 Maximum Product Subarray maximum-product-subarray.cpp O(n) DP O(1)
153 Find Minimum in Rotated Sorted Array find-minimum-in-rotated-sorted-array.c O(log(n)) 二分查找 O(log(n))
154 Find Minimum in Rotated Sorted Array II find-minimum-in-rotated-sorted-array-ii.c O(n) 二分查找 O(n)
155 Min Stack min-stack.cpp O(1) 最小栈 O(n)
160 Intersection of Two Linked Lists intersection-of-two-linked-lists.cpp O(n) 反转链表 O(1)
162 Find Peak Element find-peak-element.cpp O(log(n)) 二分查找 O(1)
165 Compare Version Numbers compare-version-numbers.cpp O(n) 字符串分割 O(n)
166 Fraction to Recurring Decimal fraction-to-recurring-decimal.cpp O(n) 长除法 O(n)
167 Two Sum II - Input array is sorted two-sum-ii-input-array-is-sorted.cpp O(n) two-pointer O(1)
168 Excel Sheet Column Title excel-sheet-column-title.cpp O(n) 进制转换 O(1)
169 Majority Element majority-element.cpp O(n) 摩尔投票算法 O(1)
171 Excel Sheet Column Number excel-sheet-column-number.cpp O(n) 进制转换 O(1)
172 Factorial Trailing Zeroes factorial-trailing-zeroes.cpp O(1) 阶乘末尾0个数 O(1)
173 Binary Search Tree Iterator binary-search-tree-iterator.cpp O(1) 中序遍历非递归实现 O(log(n))
174 Dungeon Game dungeon-game.c O(m*n) DP+滚动数组 O(min(m,n))
175 Combine Two Tables combine-two-tables.sql 左连接
176 Second Highest Salary second-highest-salary.sql max()函数
177 Nth Highest Salary nth-highest-salary.sql dense_rank()函数
178 Rank Scores rank-scores.sql dense_rank()函数
179 Largest Number largest-number.c O(nlog(n)) 字符串排序 O(n)
180 Consecutive Numbers consecutive-numbers.sql lag()/lead()函数
181 Employees Earning More Than Their Managers employees-earning-more-than-their-managers.sql 自连接
182 Duplicate Emails duplicate-emails.sql 查找重复元素
183 Customers Who Never Order customers-who-never-order.sql 左连接不包含内连接
184 Department Highest Salary department-highest-salary.sql 左连接+子查询
185 Department Top Three Salaries department-top-three-salaries.sql 窗口函数: dense_rank()
187 Repeated DNA Sequences repeated-dna-sequences.c O(n) hashset+位压缩 O(n)
189 Rotate Array rotate-array.cpp O(n) 递归 O(1)
190 Reverse Bits reverse-bits.cpp O(1) 《Hacker's Delight》图 7-1 O(1)
191 umber of 1 Bits number-of-1-bits.cpp O(1) 《Hacker's Delight》图 5-2 O(1)
192 Word Frequency word-frequency.sh O(nlog(n)) declare + sed + sort命令 O(n)
193 Valid Phone Numbers valid-phone-numbers.sh grep命令+正则
195 Tenth Line tenth-line.sh sed命令
196 Delete Duplicate Emails delete-duplicate-emails.sql with+rank()
197 Rising Temperature rising-temperature.sql 自连接
198 House Robber house-robber.cpp O(n) DP O(1)
199 Binary Tree Right Side View binary-tree-right-side-view.cpp O(n) BFS O(n)
200 Number of Islands number-of-islands.cpp O(m*n) 地图DFS O(m*n)
201 Bitwise AND of Numbers Range bitwise-and-of-numbers-range.cpp O(log(n)) 位操作 O(1)
202 Happy Number happy-number.c 模拟 O(1)
203 Remove Linked List Elements remove-linked-list-elements.c O(n) 遍历 O(1)
204 Count Primes count-primes.c O(n) 欧拉筛素数法 O(n)
205 Isomorphic Strings isomorphic-strings.cpp O(n) 字典 O(1)
206 Reverse Linked List reverse-linked-list.cpp O(n) 单链翻转 O(1)
207 Course Schedule course-schedule.cpp O(V+E) 拓扑排序 O(V+E)
208 Implement Trie (Prefix Tree) implement-trie-prefix-tree.c O(n) 前缀树 O(26^n)
209 Minimum Size Subarray Sum minimum-size-subarray-sum.c O(n) 滑动窗口 O(1)
211 Design Add and Search Words Data Structure design-add-and-search-words-data-structure.c O(n) 前缀树 O(26^n)
215 Kth Largest Element in an Array kth-largest-element-in-an-array.cpp O(n) std::nth_element O(1)
217 Contains Duplicate contains-duplicate.c O(n) hashset O(n)
219 Contains Duplicate II contains-duplicate-ii.cpp O(n) 滑动窗口+hashset O(n)
221 Maximal Square maximal-square.cpp O(m*n) DP+状态压缩 O(n)
223 Rectangle Area rectangle-area.cpp O(1) 矩形面积 O(1)
224 Basic Calculator basic-calculator.cpp O(n) 表达式求值 O(n)
227 Basic Calculator II basic-calculator-ii.cpp O(n) 表达式求值 O(n)
228 Summary Ranges summary_ranges.py O(n) 双指针 O(n)
231 Power of Two power_of_two.py O(1) 位运算 O(1)
233 Number of Digit One number-of-digit-one.c O(log10(n)) 数学推导+递归 O(log10(n))
234 Palindrome Linked List palindrome-linked-list.c O(n) 反转链表+双指针比较 O(1)
236 Ugly Number ugly_number.py O(log(n)) 素数 O(1)
237 Delete Node in a Linked List delete-node-in-a-linked-list.c O(1) 链表 O(1)
239 Sliding Window Maximum sliding-window-maximum.c O(n) 单调队列 O(n)
240 Search a 2D Matrix II search-a-2d-matrix-ii.cpp O(m+n) 二叉查找树 O(1)
242 Valid Anagram valid-anagram.cpp O(n) 字符字典 O(1)
258 Add Digits add_digits.py O(1) 树根 O(1)
260 Single Number III single-number-iii.c O(n) 异或+分组 O(1)
264 Ugly Number II ugly-number-ii.c O(n) DP O(n)
268 Missing Number missing-number.c O(n) 等差数列求和 O(1)
274 H-Index h-index.cpp O(n) 桶排序 O(n)
275 H-Index II h-index-ii.cpp O(log(n)) 二分 O(n)
278 First Bad Version first-bad-version-test.cpp O(log(n)) 二分 O(1)
282 Expression Add Operators expression-add-operators.c O(4^n) DFS O(n)
283 Move Zeroes move-zeroes.cpp O(n) 交换操作 O(1)
287 find-the-duplicate-number find-the-duplicate-number.cpp O(n) 快慢指针 O(1)
289 Game of Life game-of-life.c O(m*n) 遍历+位操作 O(1)
290 Word Pattern word-pattern.cpp O(n) map + split O(1)
292 Nim Game nim-game.c O(1) 博弈论 O(1)
293 Sliding Window Maximum sliding-window-maximum.c O(n) 双向链表+单调队列 O(n)
295 Find Median from Data Stream find-median-from-data-stream.cpp O(nlog(n)) 优先队列/堆 O(n)
299 Bulls and Cows bulls-and-cows.cpp O(n) 遍历 O(n)
304 Range Sum Query 2D - Immutable range_sum_query_2d_immutable.py O(m*n) 动态规划 O(m*n)
326 Power of Three power_of_three.py O(1) 质数 O(1)
352 Data Stream as Disjoint Intervals data-stream-as-disjoint-intervals.c O(n) 桶遍历 O(n)
365 Water and Jug Problem water-and-jug-problem.c O(log(n)) gcd O(1)
367 Valid Perfect Square valid-perfect-square.cpp O(log4(n)) 二分查找 O(1)
372 Super Pow super-pow.cpp O(n) 快速幂 O(1)
380 Insert Delete GetRandom O(1) insert-delete-getrandom-o1.c O(1) HashMap O(n)
384 Shuffle an Array shuffle-an-array.c O(n) Fisher–Yates shuffle 洗牌算法 O(n)
393 UTF-8 Validation utf-8-validation.c O(n) UTF-8编码验证 O(1)
397 Integer Replacement integer-replacement.c O(log(n)) 贪心 O(1)
400 Nth Digit nth-digit.cpp O(log10(n)) 递归 O(log10(n))
406 Queue Reconstruction by Height queue-reconstruction-by-height.c O(n^2) 快速排序+插入 O(n)
416 Partition Equal Subset Sum partition-equal-subset-sum.cpp O(n*sum/2) 01背包 O(sum/2)
429 N-ary Tree Level Order Traversal n-ary-tree-level-order-traversal.cpp O(n) 广度优先遍历 O(n)
434 Number of Segments in a String number-of-segments-in-a-string.c O(n) 遍历 O(1)
435 Non-overlapping Intervals non-overlapping-intervals.c O(nlog(n)) 贪心 O(nlog(n))
436 Find Right Interval find-right-interval.c O(nlog(n)) 排序+二分查找 O(n)
437 Path Sum III path-sum-iii.c O(n) 前缀和+HashMap O(n)
447 Number of Boomerangs number-of-boomerangs.c O(n^2) HashMap O(n)
451 Sort Characters By Frequency sort-characters-by-frequency.cpp O(n) 桶排序 O(n)
454 4Sum II 4sum-ii.cpp O(n^2) HashMap O(n^2)
460 LFU Cache lfu-cache.cpp O(1) 双向链表+双HashMap实现LFU O(n)
463 Island Perimeter island-perimeter.cpp O(m*n) 遍历 O(1)
473 Matchsticks to Square matchsticks-to-square.c DFS O(n)
475 Heaters heaters.cpp O(nlog(n)) 排序 O(1)
478 Generate Random Point in a Circle generate-random-point-in-a-circle.cpp O(1) 极坐标 O(1)
498 Diagonal Traverse diagonal-traverse.cpp O(m*n) 模拟 O(1)
513 Find Bottom Left Tree Value find-bottom-left-tree-value.c O(n) 递归 O(log(n))
528 Random Pick with Weight random-pick-with-weight.c O(log(n)) 前缀和数组+二分查找 O(n)
537 Complex Number Multiplication complex-number-multiplication.go O(n) 复数相乘 O(1)
540 Single Element in a Sorted Array single-element-in-a-sorted-array.cpp O(log(n)) 二分查找 O(1)
543 Diameter of Binary Tree diameter-of-binary-tree.cpp O(n) 二叉树DFS O(log(n))
554 Brick Wall brick-wall.cpp O(m*n) 前缀和+HashMap O(m*n)
557 Reverse Words in a String III reverse-words-in-a-string-iii.c O(n) 遍历 O(n)
558 Logical OR of Two Binary Grids Represented as Quad-Trees logical-or-of-two-binary-grids-represented-as-quad-trees.cpp O(n) 递归 O(n)
581 Shortest Unsorted Continuous Subarray shortest-unsorted-continuous-subarray.c O(n) 遍历 O(1)
590 N-ary Tree Postorder Traversal n-ary-tree-postorder-traversal.cpp O(n) 递归/迭代 O(n)
611 Valid Triangle Number valid-triangle-number.c O(n^2) 双指针 O(1)
622 Design Circular Queue design-circular-queue.cpp O(1) 循环队列 O(n)
640 Solve the Equation solve-the-equation.cpp O(n) 解一元一次方程 O(1)
643 Maximum Average Subarray I maximum-average-subarray-i.c O(n) 滑动窗口 O(1)
661 Image Smoother image-smoother.cpp O(m*n) 遍历(STL并行化) O(m*n)
677 Map Sum Pairs map-sum-pairs.cpp O(n) 前缀树 O(26^n)
682 Baseball Game baseball-game.cpp O(n) O(n)
690 Employee Importance employee-importance.cpp O(n) 哈希表 O(n)
713 Subarray Product Less Than K subarray-product-less-than-k.c O(n) 滑动窗口 O(1)
725 Split Linked List in Parts split-linked-list-in-parts.cpp O(n) 求余 O(n)
729 My Calendar I my-calendar-i.cpp O(log(n)) 借助std::map模拟平衡树 O(n)
739 Daily Temperatures daily-temperatures.c O(n) 单调非递增栈 O(n)
746 Min Cost Climbing Stairs min-cost-climbing-stairs.cpp O(n) 斐波拉契数列 O(1)
784 Letter Case Permutation letter-case-permutation.c O(2^n) 递归 O(2^n)
807 Max Increase to Keep City Skyline max-increase-to-keep-city-skyline.c O(2^n) 行列最大值 O(n)
810 Chalkboard XOR Game chalkboard-xor-game.c O(n) 异或 O(1)
814 Binary Tree Pruning binary-tree-pruning.c O(n) 递归 O(n)
816 Ambiguous Coordinates ambiguous-coordinates.cpp 模拟
838 Push Dominoes push-dominoes.c O(n) 遍历 O(n)
844 Backspace String Compare backspace-string-compare.c O(n) O(1)
855 Exam Room exam-room.cpp O(log(n)) 平衡树+hashMap O(n)
861 Score After Flipping Matrix score-after-flipping-matrix.c O(m*n) 贪心 O(1)
863 All Nodes Distance K in Binary Tree all-nodes-distance-k-in-binary-tree.c O(n) hash表+递归 O(n)
865 Smallest Subtree with all the Deepest Nodes smallest-subtree-with-all-the-deepest-nodes.c O(n) 递归 O(n)
869 Reordered Power of 2 reordered-power-of-2.c O(log(n)) 模拟 O(1)
870 Advantage Shuffle advantage-shuffle.c O(nlog(n)) 田忌赛马 O(n)
876 Middle of the Linked List middle-of-the-linked-list.cpp O(n) 快慢指针 O(1)
881 Boats to Save People boats-to-save-people.c O(nlog(n)) 贪心 O(1)
900 RLE Iterator rle-iterator.c O(n) 模拟 O(n)
947 Most Stones Removed with Same Row or Column most-stones-removed-with-same-row-or-column.c O(n) 并查集(路径压缩+按秩合并) O(n)
957 Prison Cells After N Days prison-cells-after-n-days/prison-cells-after-n-days.c O(1) 位操作+计算周期 O(1)
967 Numbers With Same Consecutive Differences numbers-with-same-consecutive-differences.c DFS O(n)
985 Sum of Even Numbers After Queries sum-of-even-numbers-after-queries.c O(n) 偶数运算 O(n)
991 Broken Calculator broken-calculator.c O(log(n)) 贪心 O(1)
1006 Clumsy Factorial clumsy-factorial.c O(1) 数学推导 O(1)
1034 Coloring A Border coloring-a-border.c O(m*n) 迷宫DFS O(m*n)
1054 Distant Barcodes distant-barcodes.c O(n) 迷宫DFS O(n)
1074 Number of Submatrices That Sum to Target number-of-submatrices-that-sum-to-target.cpp O(n^2*m) 前缀和+hash O(m*n)
1094 Car Pooling car-pooling.cpp O(n) 差分数组 O(n)
1104 Path In Zigzag Labelled Binary Tree path-in-zigzag-labelled-binary-tree.c O(log(n)) 数学推导 O(log(n))
1114 Print in Order print-in-order.cpp O(n) std::promise 线程锁 O(n)
1115 Print FooBar Alternately print-foobar-alternately.cpp O(n) std::atomic std::condition_variable线程锁 O(n)
1116 Print Zero Even Odd print-zero-even-odd.cpp O(n) O(n)
1123 Lowest Common Ancestor of Deepest Leaves smallest-subtree-with-all-the-deepest-nodes.c O(n) 递归 O(n)
1129 Shortest Path with Alternating Colors shortest-path-with-alternating-colors.cpp O(E) DFS最短路 O(E)
1178 Number of Valid Words for Each Puzzle number-of-valid-words-for-each-puzzle.c O((2^7)*n) hashMap+位压缩 O(n)
1139 Design Underground System design-underground-system.cpp O(1) 双hashMap+自定义hash O(n)
1219 Path with Maximum Gold path-with-maximum-gold.cpp 迷宫DFS+剪枝 O(m*n)
1261 Find Elements in a Contaminated Binary Tree find-elements-in-a-contaminated-binary-tree.c O(log(n)) 完全二叉树深度 O(1)
1333 Filter Restaurants by Vegan-Friendly, Price and Distance filter-restaurants-by-vegan-friendly-price-and-distance.c O(nlog(n)) 排序 O(log(n))
1367 Linked List in Binary Tree linked-list-in-binary-tree-test.c 二次递归
1379 Find a Corresponding Node of a Binary Tree in a Clone of That Tree find-a-corr-node-of-a-binary-tree-in-a-clone-of-that-tree.cpp O(n) 二叉树DFS O(n)
1389 Create Target Array in the Given Order create-target-array-in-the-given-order-test.c O(n^2) 线性表插入 O(n)
1391 Check if There is a Valid Path in a Grid check-if-there-is-a-valid-path-in-a-grid.c O(m*n) 模拟 O(1)
1424 Diagonal Traverse II diagonal-traverse-ii.cpp O(n) BFS O(log(n))
1464 Maximum Product of Two Elements in an Array maximum-product-of-two-elements-in-an-array.cpp O(n) 遍历 O(1)
1472 Design Browser History design-browser-history.cpp O(1) 线性表 O(n)
1503 Last Moment Before All Ants Fall Out of a Plank last-moment-before-all-ants-fall-out-of-a-plank.cpp O(n) 遍历 O(1)
1636 Sort Array by Increasing Frequency sort-array-by-increasing-frequency.c O(nlog(n)) 桶排序 O(n)
1706 Where Will the Ball Fall where-will-the-ball-fall.cpp O(m*n) 模拟 O(n)
1716 Calculate Money in Leetcode Bank calculate-money-in-leetcode-bank.cpp O(1) 等差数列求和 O(1)
1718 Construct the Lexicographically Largest Valid Sequence construct-the-lexicographically-largest-valid-sequence.c O(1) DFS/打表 O(n)
1774 Closest Dessert Cost closest-dessert-cost.c O(n*3^m) DFS/DP O(n)
1763 Longest Nice Substring longest-nice-substring.c O(n) 滑动窗口 O(n)
1822 Sign of the Product of an Array sign-of-the-product-of-an-array.c O(n) 遍历 O(1)
1823 Find the Winner of the Circular Game find-the-winner-of-the-circular-game.cpp O(n) DP O(1)
1828 Queries on Number of Points Inside a Circle queries-on-number-of-points-inside-a-circle.cpp O(n^2) 排序+二分查找 O(n)
1833 Maximum Ice Cream Bars maximum-ice-cream-bars.c O(n) 贪心+桶排序 O(n)
1882 Process Tasks Using Servers process-tasks-using-servers.cpp O(nlog(n)) 双优先队列 O(n)
1845 Seat Reservation Manager seat-reservation-manager.cpp O(log(n)) 优先队列 O(n)
1904 The Number of Full Rounds You Have Played the-number-of-full-rounds-you-have-played.c O(1) 模拟 O(1)
1942 The Number of the Smallest Unoccupied Chair the-number-of-the-smallest-unoccupied-chair.cpp O(nlog(n)) 优先队列 O(n)
2007 Find Original Array From Doubled Array find-original-array-from-doubled-array.cpp O(nlog(n)) 排序+队列 O(n)
2043 Simple Bank System simple-bank-system.c O(1) 模拟 O(n)
2786 Visit Array Positions to Maximize Score visit-array-positions-to-maximize-score.cpp O(n) DP+状态压缩 O(1)
3084 Count Substrings Starting and Ending with Given Character count-substrings-starting-and-ending-with-given-character.c O(n) 排列组合 O(1)
3179 Find the N-th Value After K Seconds find-the-n-th-value-after-k-seconds.cpp O(1) 杨辉三角+费马小定理 O(n)
面试题 17.17 多次搜索 multi-search-lcci.c O(m*n) 前缀树 O(m*n)

补充