LeetCode总结

最近完成了www.leetcode.com的online judge中151道算法题目。除各个题目有特殊巧妙的解法以外,大部分题目都是经典的算法或者数据结构,因此做了如下小结,具体的解题思路可以搜索我的博客:LeetCode题解

题目算法数据结构注意事项
Clone GraphBFS哈希表
Word Ladder IIBFS哈希表
Surrounded RegionsBFS矩阵
Word LadderBFSN/A
Binary Tree Level Order TraversalBFS|前序遍历队列
Binary Tree Level Order Traversal IIBFS|前序遍历队列
Binary Tree Zigzag Level Order Traversal BFS|前序遍历队列每一层顺序分别对待
Implement strStr()KMP算法N/A
Copy List with Random PointerN/A哈希表
Remove Duplicates from Sorted ArrayN/A哈希表
Remove Duplicates from Sorted Array IIN/A哈希表
Set Matrix ZeroesN/A哈希表
AnagramsN/A哈希表
First Missing PositiveN/A哈希表
Two SumN/A哈希表
Evaluate Reverse Polish NotationN/A堆栈
Largest Rectangle in HistogramN/A堆栈记录重要位置
Minimum Window SubstringN/A堆栈
Simplify PathN/A堆栈
Longest Valid ParenthesesN/A堆栈
Valid ParenthesesN/A堆栈词法分析
Container With Most WaterN/A堆栈记录重要位置
Reverse Words in a StringN/A堆栈翻转字符串
Best Time to Buy and Sell StockN/A数组
Best Time to Buy and Sell Stock IIN/A数组
Best Time to Buy and Sell Stock IIIN/A数组
Length of Last WordN/A数组
Search Insert PositionN/A数组
Search for a RangeN/A数组
Spiral MatrixN/A矩阵简化为子问题
Spiral Matrix IIN/A矩阵简化为子问题
LRU CacheN/A链表
Reorder ListN/A链表快慢指针&链表倒序
Linked List CycleN/A链表快慢指针
Linked List Cycle IIN/A链表快慢指针
Reverse Linked List IIN/A链表
Partition ListN/A链表
Remove Duplicates from Sorted ListN/A链表
Remove Duplicates from Sorted List IIN/A链表
Merge Two Sorted ListsN/A链表
Rotate ListN/A链表快慢指针
Reverse Nodes in k-GroupN/A链表
Swap Nodes in PairsN/A链表
Remove Nth Node From End of ListN/A链表快慢指针
Text JustificationN/A队列
CandyN/AN/A简化为子问题
Valid PalindromeN/AN/A首尾指针
Plus OneN/AN/A模拟加法运算
Valid NumberN/AN/A词法分析
Add BinaryN/AN/A模拟加法运算
Insert IntervalN/AN/A
Merge IntervalsN/AN/A
Multiply StringsN/AN/A模拟乘法运算
Trapping Rain WaterN/AN/A
Valid SudokuN/AN/A
Roman to IntegerN/AN/A
Integer to RomanN/AN/A
Palindrome NumberN/AN/A
Reverse IntegerN/AN/A
ZigZag ConversionN/AN/A
Add Two NumbersN/AN/A模拟加法运算
Median of Two Sorted ArraysN/AN/A
String to Integer (atoi)STL函数N/A
Next PermutationSTL经典算法N/A
Recover Binary Search Tree中序遍历二叉树
3Sum二分查找N/A
3Sum Closest二分查找N/A
4Sum二分查找N/A
Single Number位运算N/A
Single Number II位运算N/A
Construct Binary Tree from Preorder and Inorder Traversal前序中序遍历N/A
Binary Tree Preorder Traversal前序遍历二叉树
Flatten Binary Tree to Linked List前序遍历二叉树
Interleaving String动态规划二叉树
Unique Binary Search Trees动态规划二叉树
Word Break动态规划N/A
Word Break II动态规划N/A
Palindrome Partitioning动态规划N/A
Palindrome Partitioning II动态规划N/A
Triangle动态规划N/A
Distinct Subsequences动态规划N/A
Decode Ways动态规划N/A
Scramble String动态规划N/A
Maximal Rectangle动态规划N/A
Edit Distance动态规划N/A
Climbing Stairs动态规划N/A
Minimum Path Sum动态规划N/A
Unique Paths动态规划N/A
Unique Paths II动态规划N/A
Jump Game动态规划N/A
Jump Game II动态规划N/A
Maximum Subarray动态规划N/A
Wildcard Matching动态规划N/A
Substring with Concatenation of All Words动态规划N/A
Sort List合并排序链表快慢指针
Merge Sorted Array合并排序N/A
Construct Binary Tree from Inorder and Postorder Traversal后序中序遍历N/A
Binary Tree Postorder Traversal后续遍历二叉树
Combinations回溯N/A
Permutation Sequence回溯N/A
N-Queens回溯N/A
N-Queens II回溯N/A
Permutations回溯N/A
Permutations II回溯N/A
Combination Sum回溯N/A
Combination Sum II回溯N/A
Sudoku Solver回溯N/A
Longest Substring Without Repeating Characters回溯N/A
Max Points on a Line循环遍历N/A排除相同的点
Longest Common Prefix循环遍历N/A
Longest Palindromic Substring循环遍历N/A
Insertion Sort List插入排序链表
Rotate Image矢量旋转与平移N/A
Longest Consecutive Sequence类BFS哈希表
Search in Rotated Sorted Array类二分查找N/A
Search in Rotated Sorted Array II类二分查找N/A特殊考虑相等数据
Sqrt(x)类二分查找N/A
Pow(x, n)类二进制N/A
Divide Two Integers类二进制N/A
Gas Station类合并排序N/A
Merge k Sorted Lists类外排序N/A
Sort Colors类快速排序N/A
Remove Element类快速排序N/A
Search a 2D Matrix类杨氏矩阵N/A
Restore IP Addresses揹包问题N/A
Sum Root to Leaf Numbers递归二叉树
Binary Tree Maximum Path Sum递归二叉树
opulating Next Right Pointers in Each Node递归二叉树
Populating Next Right Pointers in Each Node II递归二叉树
Path Sum递归二叉树
Path Sum II递归二叉树
Maximum Depth of Binary Tree 递归二叉树
Minimum Depth of Binary Tree递归二叉树
Balanced Binary Tree递归二叉树
Symmetric Tree递归二叉树
Same Tree 递归二叉树
Validate Binary Search Tree递归二叉树
Unique Binary Search Trees II递归二叉树
Binary Tree Inorder Traversal递归二叉树
Pascal’s Triangle递归N/A
Pascal’s Triangle II递归N/A
Convert Sorted List to Binary Search Tree递归N/A快慢指针&反中序遍历
Convert Sorted Array to Binary Search Tree递归N/A反中序遍历
Subsets递归N/A
Subsets II递归N/A
Gray Code递归N/A
Word Search递归N/A
Count and Say递归N/A
Generate Parentheses递归N/A
Letter Combinations of a Phone Number递归N/A
Regular Expression Matching递归N/A
点赞