Algorithm Solutions

Leetcode Solutions

# Title Difficulty Blog Others
1 Two Sum Easy Two Sum
2 Add Two Numbers Medium Add Two Numbers
3 Longest Substring Without Repeating Characters Medium Longest Substring Without Repeating Characters
4 Median of Two Sorted Arrays Hard Median of Two Sorted Arrays Binary Search *
5 Longest Palindromic Substring Medium Longest Palindromic Substring dp & Manacher’s Algorithm *
6 ZigZag Conversion Medium ZigZag Conversion
7 Reverse Integer Easy Reverse Integer
8 String to Integer (atoi) Medium String to Integer (atoi)
9 Palindrome Number Easy Palindrome Number
10 Regular Expression Matching Hard Regular Expression Matching dp **
11 Container With Most Water Medium Container With Most Water
12 Integer to Roman Medium Integer to Roman
13 Roman to Integer Easy Roman to Integer
14 Longest Common Prefix Easy Longest Common Prefix
15 3Sum Medium 3Sum
16 3Sum Closest Medium 3Sum Closest
17 Letter Combinations of a Phone Number Medium Letter Combinations of a Phone Number
18 4Sum Medium 4Sum
19 Remove Nth Node From End of List Medium Remove Nth Node From End of List
20 Valid Parentheses Easy Valid Parentheses
21 Merge Two Sorted Lists Easy Merge Two Sorted Lists
22 Generate Parentheses Medium Generate Parentheses
23 Merge k Sorted Lists Hard Merge k Sorted Lists Divide Conquer & Heap Sort
24 Swap Nodes in Pairs Medium Swap Nodes in Pairs
25 Reverse Nodes in k-Group Hard Reverse Nodes in k-Group Reverse List
26 Remove Duplicates from Sorted Array Easy Remove Duplicates from Sorted Array
27 Remove Element Easy Remove Element
28 Implement strStr() Easy Implement strStr() KMP Algorithm *
29 Divide Two Integers Medium Divide Two Integers
30 Substring with Concatenation of All Words Hard Substring with Concatenation of All Words
31 Next Permutation Medium Next Permutation
32 Longest Valid Parentheses Hard Longest Valid Parentheses DP/Stack *
33 Search in Rotated Sorted Array Medium Search in Rotated Sorted Array
34 Find First and Last Position of Element in Sorted Array Medium Find First and Last Position of Element in Sorted Array
35 Search Insert Position Easy Search Insert Position
36 Valid Sudoku Medium Valid Sudoku
37 Sudoku Solver Hard Sudoku Solver Backtracking *
38 Count And Say Easy Count And Say
39 Combination Sum Medium Combination Sum
40 Combination Sum II Medium Combination Sum II
41 First Missing Positive Hard First Missing Positive Trick method
42 Trapping Rain Water Hard Trapping Rain Water Dp/Stack/Two Pointer
43 Multiply Strings Medium Multiply Strings
44 Wildcard Matching Hard Wildcard Matching DP*
45 Jump Game II Hard Jump Game II
46 Permutations Medium Permutations
47 Permutations II Medium Permutations II
48 Rotate Image Medium Rotate Image
49 Group Anagrams Medium Group Anagrams
50 Pow(x, n) Medium Pow(x, n)
53 Maximum Subarray Easy Maximum Subarray Kadane Algorithm *
56 Merge Intervals Medium Merge Intervals
57 Insert Interval Hard Insert Interval
58 Length of Last Word Easy Length of Last Word
66 Plus One Easy Plus One
67 Add Binary Easy Add Binary
69 Sqrt(x) Easy Sqrt(x)
70 Climbing Stairs Easy Climbing Stairs
71 Simplify Path Medium Simplify Path dp
72 Edit Distance Hard Edit Distance
83 Remove Duplicates from Sorted List Easy Remove Duplicates from Sorted List
88 Merge Sorted Array Easy Merge Sorted Array
94 Binary Tree Inorder Traversal Medium Binary Tree Inorder Traversal
100 Same Tree Easy Same Tree
101 Symmetric Tree Easy Symmetric Tree * Binary-Tree Traverse
102 Binary Tree Level Order Traversal Medium Binary Tree Level Order Traversal * Binary-Tree Traverse
104 Maximum Depth of Binary Tree Easy Maximum Depth of Binary Tree * Binary-Tree Traverse
107 Binary Tree Level Order Traversal II Easy Binary Tree Level Order Traversal II * Binary-Tree Traverse
108 Convert Sorted Array to Binary Search Tree Easy Convert Sorted Array to Binary Search Tree * Binary-Tree Traverse
112 Path Sum Easy Path Sum
113 Path Sum II Medium Path Sum II
121 Best Time to Buy and Sell Stock Easy Best Time to Buy and Sell Stock
122 Best Time to Buy and Sell Stock Easy Best Time to Buy and Sell Stock
123 Best Time to Buy and Sell Stock III Hard Best Time to Buy and Sell Stock III dp
144 Binary Tree Preorder Traversal Medium Binary Tree Preorder Traversal
145 Binary Tree Postorder Traversal Hard Binary Tree Postorder Traversal
188 Best Time to Buy and Sell Stock IV Hard Best Time to Buy and Sell Stock IV dp
198 House Robber Easy House Robber dp
213 House Robber II Easy House Robber II dp
236 Lowest Common Ancestor of a Binary Tree Medium Lowest Common Ancestor of a Binary Tree
279 Perfect Squares Medium Perfect Squares dp
287 Find the Duplicate Number Medium Find the Duplicate Number fast-slow-pointer
309 Best Time to Buy and Sell Stock with Cooldown Medium Best Time to Buy and Sell Stock with Cooldown dp
337 House Robber III Medium House Robber III dp
373 Find K Pairs with Smallest Sums Medium Find K Pairs with Smallest Sums
378 Kth Smallest Element in a Sorted Matrix Medium Kth Smallest Element in a Sorted Matrix
407 Trapping Rain Water II Hard Trapping Rain Water II
437 Path Sum III Easy Path Sum III
442 Find All Duplicates in an Array Medium Find All Duplicates in an Array
448 Find All Numbers Disappeared in an Array Easy Find All Numbers Disappeared in an Array
538 Convert BST to Greater Tree Easy Convert BST to Greater Tree
583 Delete Operation for Two Strings Medium Delete Operation for Two Strings dp
645 Set Mismatch Easy Set Mismatch
650 2 Keys Keyboard Medium 2 Keys Keyboard dp
669 Trim a Binary Search Tree Easy Trim a Binary Search Tree
671 Second Minimum Node In a Binary Tree Easy Second Minimum Node In a Binary Tree
687 Longest Univalue Path Easy Longest Univalue Path
714 Best Time to Buy and Sell Stock with Transaction Fee Medium Best Time to Buy and Sell Stock with Transaction Fee dp
953 Verifying an Alien Dictionary Easy Verifying an Alien Dictionary

剑指 offer

# Title Blog Category
3 二维数组中的查找 二维数组中的查找 数组、查找
4 替换空格 替换空格 字符串
5 从尾到头打印链表 从尾到头打印链表 链表
6 重建二叉树 重建二叉树 树 *
7 用两个栈实现队列 用两个栈实现队列 栈、队列
8 旋转数组的最小数字 旋转数组的最小数字 查找和排序
9 斐波那契数列 斐波那契数列 递归和循环
9_1 跳台阶 跳台阶 递归和循环
9_2 变态跳台阶 变态跳台阶 递归和循环
9_3 矩形覆盖 矩形覆盖 递归和循环
10 二进制中 1 的个数 二进制中 1 的个数 位运算
11 数值的整数次方 数值的整数次方 代码的完整性
14 调整数组顺序使奇数位于偶数前面 调整数组顺序使奇数位于偶数前面 代码的完整性、数组
15 链表中倒数第 k 个结点 链表中倒数第 k 个结点 代码的鲁棒性、链表
16 反转链表 反转链表 代码的鲁棒性、链表
17 合并两个排序的链表 合并两个排序的链表 代码的鲁棒性、链表
18 树的子结构 树的子结构 代码的鲁棒性
19 二叉树的镜像 二叉树的镜像 面试思路
20 顺时针打印矩阵 顺时针打印矩阵 画图让抽象形象化、数组
21 包含 min 函数的栈 包含 min 函数的栈 举例让抽象形象化、栈
22 栈的压入、弹出序列 栈的压入、弹出序列 举例让抽象形象化、栈
23 从上往下打印二叉树 从上往下打印二叉树 举例让抽象形象化
24 二叉搜索树的后序遍历序列 二叉搜索树的后序遍历序列 举例让抽象形象化
25 二叉树中和为某一值的路径 二叉树中和为某一值的路径 举例让抽象形象化
26 复杂链表的复制 复杂链表的复制 分解让复杂问题简单
27 二叉搜索树与双向链表 二叉搜索树与双向链表 分解让复杂问题简单*
28 字符串的排列 字符串的排列 分解让复杂问题简单*
31 连续子数组的最大和 连续子数组的最大和 时间效率、数组
32 整数中 1 出现的次数 整数中 1 出现的次数 时间效率
33 把数组排成最小的数 把数组排成最小的数 时间效率、数组 *
34 丑数 丑数 时间空间效率的平衡、数组
35 第一个只出现一次的字符 第一个只出现一次的字符 时间空间效率的平衡、字符串
36 数组中的逆序对 数组中的逆序对 时间空间效率的平衡、数组
37 两个链表的第一个公共结点 两个链表的第一个公共结点 时间空间效率的平衡、链表
38 数字在排序数组中出现的次数 数字在排序数组中出现的次数 知识迁移能力、数组
39 二叉树的深度 二叉树的深度 知识迁移能力、数组
39_2 平衡二叉树 平衡二叉树 知识迁移能力
40 数组中只出现一次的数字 数组中只出现一次的数字 知识迁移能力、数组
41 和为 S 的两个数字 和为 S 的两个数字 知识迁移能力
41_2 和为 S 的连续正数序列 和为 S 的连续正数序列 知识迁移能力
42 翻转单词顺序列 翻转单词顺序列 知识迁移能力、字符串
42_2 左旋转字符串 左旋转字符串 知识迁移能力、字符串
44 扑克牌顺子 扑克牌顺子 抽象建模能力
45 圆圈中最后剩下的数 圆圈中最后剩下的数 抽象建模能力、模拟
46 求 1+2+3+…+n 求 1+2+3+…+n 发散思维能力
47 不用加减乘除做加法 不用加减乘除做加法 发散思维能力
49 把字符串转换成整数 把字符串转换成整数 综合、字符串
51 数组中重复的数字 数组中重复的数字 数组
52 构建乘积数组 构建乘积数组 数组
53 正则表达式匹配 正则表达式匹配 字符串
54 表示数值的字符串 表示数值的字符串 字符串
55 字符流中第一个不重复的字符 字符流中第一个不重复的字符 字符串
56 链表中环的入口结点 链表中环的入口结点 链表
57 删除链表中重复的结点 删除链表中重复的结点 链表
58 二叉树的下一个结点 二叉树的下一个结点
59 对称的二叉树 对称的二叉树 树*
60 把二叉树打印成多行 把二叉树打印成多行
61 按之字形顺序打印二叉树 按之字形顺序打印二叉树
62 序列化二叉树 序列化二叉树
63 二叉搜索树的第 k 个结点 二叉搜索树的第 k 个结点
64 数据流中的中位数 数据流中的中位数 树*
65 滑动窗口的最大值 滑动窗口的最大值 栈和队列*
66 矩阵中的路径 矩阵中的路径 回溯法
67 机器人的运动范围 机器人的运动范围 回溯法

专题

# Title Category
1 二叉树相关知识点总结
2 LeetCode 题目专题 LeetCode