Leetcode题集

这篇博客深入探讨了LeetCode中关于树、分治、链表、二叉搜索树、图论、搜索/回溯、二分搜索和双指针等算法的典型问题。涵盖了如二叉树的中序遍历、查找相同结构的树、层序遍历等经典题目,还涉及二分查找、动态规划和高级算法应用。通过这些实例,读者可以提升在实际问题中应用这些算法的能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

树(Tree)

idnameDifficultySimilar problemsComments
94Binary Tree Inorder Traversal144,145,429,589,590,987,1302traversal
100Same Tree★★101,104,110,111,572,965
102Binary Tree Level Order Traversal★★107,429,872
814Binary Tree Pruning★★★669,1325
112Path Sum★★★113,437
129Sum Root to Leaf Numbers★★★257
236Lowest Common Ancestor of a Binary Tree★★★235
297Serialize and Deserialize Binary Tree★★★449
508Most Frequent Subtree Sum★★★
124Binary Tree Maximum Path Sum★★★543,687Use both children return one
968Binary Tree Cameras★★★★337,979

分治(Divide and Conquer)

idnameDifficultySimilar problemsComments
169Majority Element★★你知道茴香豆的茴有几种写法吗?
153Find Minimum in Rotated Sorted Array★★154
912Sort and Array★★★merge sort
315Count of Smaller Numbers After Self★★★★merge_sort/BIT

链表(Linked List)

idnameDifficultySimilar problemsComments
2Add Two Numbers★★445traversal
24Swap Nodes in Pairs★★reverse
206Reverse Linked List★★reverse
141Linked List Cycle★★142fast/low
23Merge k Sorted Lists★★★21priority_queue / mergesort
147Insertion Sort List★★★insertion sort
148Sort List★★★★merge sort O(1) space
707Design Linked List★★★★

二叉搜索树(BST)

idnameDifficultySimilar problemsComments
98Validate Binary Search Tree★★530inorder
700Search in a Binary Search Tree★★701binary search
230Kth Smallest Element in a BST★★★inorder
99Recover Binary Search Tree★★★inorder
108Convert Sorted Array to Binary Search Tree★★★build BST
501Find Mode in Binary Search Tree★★★inorder
450Delete Node in a BST★★★★binary search

图论(Graph)

idnameDifficultySimilar problemsComments
133Clone Graph★★138queue + hashtable
200Number of Islands★★547 695 733 827 1162grid + connected components
841Keys and Rooms★★1202DFS, connected components
207Course Schedule★★★210 802topology sorting
399Evaluate Division★★★839 952 990 721 737union find
785Is Graph Bipartite?★★★886 1042bipartition, graph coloring
997Find the Town Judge★★★in/out degrees
433Minimum Genetic Mutation★★★815 863 1129 1263unweighted shortest path / BFS
684Redundant Connection★★★★685 1319cycle, union find
743Network Delay Time★★★★787 882 924 1334weighted shortest path
847Shortest Path Visiting All Nodes★★★★864 1298BFS
332Reconstruct Itinerary★★★★Eulerian path
1192Critical Connections in a Network★★★★Tarjan
943Find the Shortest Superstring★★★★★980 996Hamiltonian path (DFS / DP)
959Regions Cut By Slashes★★★★★union find / grid + CCs

搜索/回溯(BFS/DFS)

idnameDifficultySimilar problemsComments
17Letter Combinations of a Phone Number★★39 40 77 78 90 216Combination
46Permutations★★47 784 943 996Permutation
22Generate Parentheses★★★301DFS
37Sudoku Solver★★★51 52DFS
79Word Search★★★212DFS
127Word Ladder★★★★126 752 818BFS
54201 Matrix★★★675 934BFS
698Partition to K Equal Sum Subsets★★★93 131 241 282 842Partition

二分搜索(Binary Search)

idnameDifficultySimilar problemsComments
35Search Insert Position★★34 704 981upper_bound
33Search in Rotated Sorted Array★★★81 153 154 162 852rotated / peak
69Sqrt(x)★★★upper_bound
74Search a 2D Matrix★★★treat 2d as 1d
875Koko Eating Bananas★★★1011guess ans and check
4Median of Two Sorted Arrays★★★★
378Kth Smallest Element in a Sorted Matrix★★★★668kth + matrix
719Find K-th Smallest Pair Distance★★★★786kth + two pointers

双指针(Two Pointers)

idnameDifficultySimilar problemsComments
11Container With Most Water★★42
125Valid Palindrome★★455
917Reverse Only Letters★★925 986 855
167Two Sum II – Input array is sorted★★★15 16
977Squares of a Sorted Array★★merge sort
992Subarrays with K Different Integers★★★★

高级(Advanced)

idnameDifficultySimilar problemsComments
208Implement Trie (Prefix Tree)★★★648 676 677 720 745 211Trie
307Range Sum Query – Mutable★★★BIT/Segment Tree
901Online Stock Span★★★907 1019monotonic stack
239Sliding Window Maximum★★★monotonic queue

动态规划(DP)

idnameDifficultySimilar problemsComments
70Climbing Stairs746 1137I: O(n), S = O(n), T = O(n)
303Range Sum Query – Immutable1218I: O(n), S = O(n), T = O(n)
53Maximum Subarray★★121I: O(n), S = O(n), T = O(n)
62Unique Paths★★63 64 120 174 931 1210I: O(mn), S = O(mn), T = O(mn)
85Maximal Rectangle★★★221 304 1277I: O(mn), S = O(mn), T = O(mn)
198House Robber★★★213 309 740 790 801I: O(n), S = O(3n), T = O(3n)
279Perfect Squares★★★I: n, S = O(n), T = O(n*sqrt(n))
139Word Break★★★140 818
300Longest Increasing Subsequence★★★673 1048I: O(n), S = O(n), T = O(n^2)
6Unique Binary Search Trees★★★I: O(n), S = O(n), T = O(n^2)
96Unique Binary Search Trees★★★
1105Filling Bookcase Shelves★★★I: O(n) + t, S = O(n), T = O(n^2)
131Palindrome Partitioning★★★89I: O(n), S = O(2^n), T = O(2^n)
72Edit Distance★★★10 44 97 115 583I: O(m+n), S = O(mn), T = O(mn)
1139Largest 1-Bordered Square★★★I: O(mn), S = O(mn) T = O(mn*min(n,m))
688Knight Probability in Chessboard★★★576 935I: O(mn) + k S = O(kmn), T = O(kmn)
322Coin Change★★★377 416 494 1043 1049 1220 1230 1262 1269I: O(n) + k, S = O(n), T = O(kn)
813Largest Sum of Averages★★★★1278 1335 410I: O(n) + k S = O(n*k), T = O(kn^2)
1223Dice Roll Simulation★★★★I: O(n) + k + p S = O(k*p), T = O(n^2kp)
312Burst Balloons★★★★664 1024 1039 1140 1130I: O(n), S = O(n^2), T = O(n^3)
741Cherry Pickup★★★★I: O(n^2), S = O(n^3), T = O(n^3)
546Remove Boxes★★★★★I: O(n), S = O(n^3), T = O(n^4)
943Find the Shortest Superstring★★★★★980 996 1125I: O(n) S = O(n*2^n), T = (n2*2n)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值