LeetCode 题解

LeetCode 题解专栏收录了常见的算法题目解法,涵盖思路分析、多语言代码实现(Python/Go)以及复杂度分析,帮助你高效准备算法面试。

题目分类

普通题

基础算法题,适合入门练习和巩固基础知识点。

题号题目题号题目
12Integer to Roman 数字转罗马串26Remove Duplicates from Sorted Array 已排序数组原地去重
28Implement strStr()34Find First and Last Position of Element in Sorted Array
36Valid Sudoku 判断部分数独图是否有效50Pow(x, n) 实现pow乘方函数
60Permutation Sequence 第 K 个字典序排列75Sort Colors 荷兰国旗问题
89Gray Code 格雷码112Path Sum
152Maximum Product Subarray162Find Peak Element
165Compare Version Numbers 版本号比较168Excel Sheet Column Title
172Factorial Trailing Zeroes173Binary Search Tree Iterator
202Happy Number 快乐数204Count Primes
205Isomorphic Strings413Arithmetic Slices 算术切片
437Path Sum III451Sort Characters By Frequency
503Next Greater Element II567Permutation in String 字符串中的组合
647Palindromic Substrings 回文子字符串859Buddy Strings
969Pancake Sorting 翻转排序970Powerful Integers 平方数
971Flip Binary Tree To Match Preorder Traversal977Squares of a Sorted Array
985Sum of Even Numbers After Queries989Add to Array-Form of Integer
997Find the Town Judge1002Find Common Characters 寻找公共字符
1004Max Consecutive Ones III1018Binary Prefix Divisible By 5
1078Occurrences After Bigram636Exclusive Time of Functions
-String to Integer (atoi) 字符串转数字-字符串翻转
-矩阵旋转

好题

经典高频面试题,值得反复思考和练习。

分类题目链接
二叉树Construct Binary Tree 系列
Populating Next Right Pointers in Each Node 系列
二叉树与链表专题
Validate Binary Search Tree 验证二叉搜索树
Lowest Common Ancestor of a Binary Tree
Convert Sorted List to Binary Search Tree
Balanced Binary Tree
Unique Binary Search Trees
Unique Binary Search Trees II
Flip Binary Tree To Match Preorder Traversal
动态规划Decode Ways 系列
Word Break 系列
Best Time to Buy and Sell Stock 买卖股票最佳时间系列
Minimum Cost For Tickets 买票的最小花费
Climbing Stairs 爬楼梯系列
Unique Binary Search Trees
House Robber 打家劫舍系列
回溯Combination Sum 系列
Palindrome Partitioning 回文子串分割
Letter Tile Possibilities
链表LRU cache
二分查找Search in Rotated Sorted Array 旋转数组查找
位运算Single Number 系列
Counting Bits 位计数
Bitwise AND of Numbers Range
Reverse Bits 逆置位序列
Sum of Two Integers
Divide Two Integers 实现除法
滑动窗口Longest Substring Without Repeating Characters
Minimum ASCII Delete Sum for Two Strings
其他经典3Sum
Gas Station 加油问题
Candy 分糖果
Kth Largest Element in an Array 第 K 大的数
Two City Scheduling
Video Stitching
Divisor Game
Stone Game 石子游戏
Longest Univalue Path
Remove Sub-Folders from the Filesystem
Queries on a Permutation With Key
Capacity To Ship Packages Within D Days
Maximum Sum of Two Non-Overlapping Subarrays
Insufficient Nodes in Root to Leaf Paths
Smallest Subsequence of Distinct Characters
单词阶梯系列

难题

进阶算法挑战,培养抽象思维和解决复杂问题的能力。

题目链接
37Sudoku Solver 数独解题器
952Largest Component Size by Common Factor
-正则匹配系列

通用技巧

跨题型的通用解题方法和模板。

技巧链接
常用 STL 操作常用 STL 操作
滑动窗口专题滑动窗口专题

核心知识点

  • 滑动窗口 - 双指针技巧,高效处理子数组/子串问题
  • 二分查找 - 有序数据的高效搜索策略
  • 动态规划 - 最优子结构问题的分解与求解
  • DFS/BFS - 树和图的遍历方式
  • 回溯算法 - 枚举所有可能解的搜索策略
  • 位运算 - 利用位操作优化空间和时间复杂度

每道题解都包含清晰的思路分析、多语言实现代码以及复杂度分析,建议按题型系统练习。