Convert Figma logo to code with AI

youngyangyang04 logoleetcode-master

《代码随想录》LeetCode 刷题攻略:200道经典题目刷题顺序,共60w字的详细图解,视频难点剖析,50余张思维导图,支持C++,Java,Python,Go,JavaScript等多语言版本,从此算法学习不再迷茫!🔥🔥 来看看,你会发现相见恨晚!🚀

59,075
12,243
59,075
229

Top Related Projects

18,045

LeetCode Problems' Solutions

Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)

✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解

刷算法全靠套路,认准 labuladong 就够了!English version supported! Crack LeetCode, not only how, but also why.

Everything you need to know to get the job.

Quick Overview

LeetCode-Master is a comprehensive guide and resource repository for LeetCode problem-solving, focusing on data structures and algorithms. It provides detailed explanations, solutions, and learning paths for various coding interview questions, primarily in C++.

Pros

  • Extensive coverage of LeetCode problems with detailed explanations
  • Well-organized content with clear learning paths for different topics
  • Includes both theoretical concepts and practical problem-solving approaches
  • Active community and regular updates

Cons

  • Primarily focused on C++, which may not be ideal for users of other programming languages
  • Some explanations and comments are in Chinese, potentially limiting accessibility for non-Chinese speakers
  • The large volume of content might be overwhelming for beginners

Getting Started

  1. Clone the repository:

    git clone https://github.com/youngyangyang04/leetcode-master.git
    
  2. Navigate to the desired topic or problem in the repository structure.

  3. Read the README files for each section to understand the learning path and problem-solving strategies.

  4. Study the provided solutions and explanations for each problem.

  5. Practice solving problems on your own, referring to the guide when needed.

  6. Join the community discussions and contribute your own solutions or improvements.

Competitor Comparisons

18,045

LeetCode Problems' Solutions

Pros of leetcode

  • Offers solutions in multiple programming languages (C++, Python, Java, etc.)
  • Includes detailed explanations and time/space complexity analysis for each solution
  • Covers a wide range of LeetCode problems, including many hard-level questions

Cons of leetcode

  • Less structured learning path compared to leetcode-master
  • Lacks comprehensive categorization of problems by topic or difficulty
  • May not provide as many beginner-friendly explanations or step-by-step guides

Code Comparison

leetcode (C++ solution for Two Sum):

vector<int> twoSum(vector<int>& nums, int target) {
    unordered_map<int, int> map;
    for (int i = 0; i < nums.size(); i++) {
        if (map.find(target - nums[i]) != map.end())
            return {map[target - nums[i]], i};
        map[nums[i]] = i;
    }
    return {};
}

leetcode-master (C++ solution for Two Sum):

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> map;
        for (int i = 0; i < nums.size(); i++) {
            auto iter = map.find(target - nums[i]);
            if (iter != map.end()) {
                return {iter->second, i};
            }
            map.insert(pair<int, int>(nums[i], i));
        }
        return {};
    }
};

Both repositories provide similar solutions, but leetcode-master's code is wrapped in a class and uses slightly different syntax for map insertion.

Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)

Pros of LeetCodeAnimation

  • Provides animated visualizations of algorithms, making complex concepts easier to understand
  • Offers solutions in multiple programming languages, catering to a wider audience
  • Includes a variety of problem-solving approaches for each algorithm

Cons of LeetCodeAnimation

  • Less comprehensive coverage of LeetCode problems compared to leetcode-master
  • Animations may not be as helpful for advanced users who prefer text-based explanations
  • Updates and new content are less frequent than leetcode-master

Code Comparison

LeetCodeAnimation (Python):

def twoSum(nums, target):
    hash_table = {}
    for i, num in enumerate(nums):
        if target - num in hash_table:
            return [hash_table[target - num], i]
        hash_table[num] = i
    return []

leetcode-master (C++):

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> map;
        for (int i = 0; i < nums.size(); i++) {
            auto it = map.find(target - nums[i]);
            if (it != map.end()) {
                return {it->second, i};
            }
            map[nums[i]] = i;
        }
        return {};
    }
};

Both repositories offer valuable resources for learning and practicing LeetCode problems. LeetCodeAnimation excels in visual explanations, while leetcode-master provides more comprehensive coverage and frequent updates. The choice between the two depends on individual learning preferences and goals.

✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解

Pros of LeetCode-Go

  • Written in Go, offering solutions for developers focused on this language
  • Includes detailed explanations and complexity analysis for each solution
  • Provides a comprehensive set of LeetCode problems with well-organized categories

Cons of LeetCode-Go

  • Limited to Go language, while leetcode-master covers multiple languages
  • May not be as beginner-friendly as leetcode-master, which offers more step-by-step guidance
  • Lacks the extensive problem-solving strategies and patterns found in leetcode-master

Code Comparison

LeetCode-Go (Go):

func twoSum(nums []int, target int) []int {
    m := make(map[int]int)
    for i, num := range nums {
        if j, ok := m[target-num]; ok {
            return []int{j, i}
        }
        m[num] = i
    }
    return nil
}

leetcode-master (C++):

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> map;
        for (int i = 0; i < nums.size(); i++) {
            auto it = map.find(target - nums[i]);
            if (it != map.end()) {
                return {it->second, i};
            }
            map[nums[i]] = i;
        }
        return {};
    }
};

Both repositories offer high-quality LeetCode solutions, but they cater to different audiences. LeetCode-Go is ideal for Go developers seeking in-depth explanations, while leetcode-master provides a more comprehensive, multi-language approach with additional learning resources.

刷算法全靠套路,认准 labuladong 就够了!English version supported! Crack LeetCode, not only how, but also why.

Pros of fucking-algorithm

  • More comprehensive explanations of algorithms and data structures
  • Covers a wider range of topics beyond just LeetCode problems
  • Provides in-depth analysis and thought processes for problem-solving

Cons of fucking-algorithm

  • Less frequently updated compared to leetcode-master
  • Primarily written in Chinese, which may be a barrier for non-Chinese speakers
  • Fewer problems covered overall

Code Comparison

leetcode-master:

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> map;
        for (int i = 0; i < nums.size(); i++) {
            if (map.find(target - nums[i]) != map.end()) {
                return {map[target - nums[i]], i};
            }
            map[nums[i]] = i;
        }
        return {};
    }
};

fucking-algorithm:

vector<int> twoSum(vector<int>& nums, int target) {
    unordered_map<int, int> indices;
    for (int i = 0; i < nums.size(); i++) {
        int complement = target - nums[i];
        if (indices.count(complement)) {
            return {indices[complement], i};
        }
        indices[nums[i]] = i;
    }
    return {};
}

Both repositories provide high-quality content for algorithm learning, with leetcode-master focusing more on LeetCode problems and fucking-algorithm offering broader algorithmic insights. The choice between them depends on the user's language preference and specific learning goals.

Everything you need to know to get the job.

Pros of interviews

  • Broader scope covering various CS topics beyond just LeetCode problems
  • Includes system design and behavioral interview preparation
  • Content in English, making it accessible to a wider international audience

Cons of interviews

  • Less structured approach to problem-solving compared to leetcode-master
  • Not as frequently updated as leetcode-master
  • Lacks detailed explanations for each problem solution

Code Comparison

interviews:

public ListNode reverseList(ListNode head) {
    ListNode prev = null;
    while (head != null) {
        ListNode next = head.next;
        head.next = prev;
        prev = head;
        head = next;
    }
    return prev;
}

leetcode-master:

class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        ListNode* temp;
        ListNode* cur = head;
        ListNode* pre = NULL;
        while(cur) {
            temp = cur->next;
            cur->next = pre;
            pre = cur;
            cur = temp;
        }
        return pre;
    }
};

Both repositories provide solutions to common coding interview problems, but leetcode-master offers a more structured approach with detailed explanations in Chinese. interviews covers a broader range of topics but with less depth in problem explanations. The code samples show similar approaches to reversing a linked list, with interviews using Java and leetcode-master using C++.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

代码随想录 · LeetCode-Master

🌍 海外英文版 · 🌍🇸 英文仓库 · 🇨🇳 国内在线阅读 · 🇨 Gitee 同步

stars forks issues contributors

一套 循序渐进、少走弯路 的刷题计划。 题目已按知识脉络与难度 排好顺序,每题配 **图文题解 + 视频讲解**。 适合从零到进阶、系统化掌握数据结构与算法。


🔗 快速入口


📚 为什么选这套刷题路线?

  • **不再海选题目:README 就是刷题路线,按顺序刷**即可。
  • 全链路学习体验:每个专题含「理论基础 → 实战题目 → 总结复盘」。
  • 经典高频必会:题目均为高频面试题与典型考点。
  • 多语言覆盖:除 C++ 主线,还有社区贡献的多语言实现。


🚀 如何使用本攻略

  1. 从头开始:按模块顺序「数组 → 链表 → 哈希表 → … → 图论」。
  2. **带着问题学**:每个模块先看「理论基础」,再刷对应题单。
  3. 及时复盘:刷完一个模块,阅读「总结篇」,形成**知识闭环**。
  4. 语言不设限:题解以 C++ 讲解为主,配多语言代码,思路通用。

**建议**:新手先刷「数组/链表/哈希/字符串」,再进阶到「二叉树/回溯/贪心/动态规划/图论」。


🧭 刷题总目录(可折叠)

已根据学习曲线优化排序;下方仅展示每章前若干题目,完整清单请展开查看。

前序 · 打基础
数组
  1. 数组过于简单,但你该了解这些!
  2. 数组:704.二分查找
  3. 数组:27.移除元素
  4. 数组:977.有序数组的平方
  5. 数组:209.长度最小的子数组
  6. 数组:区间和
  7. 数组:开发商购买土地
  8. 数组:59.螺旋矩阵II
  9. 数组:总结篇
链表
  1. 关于链表,你该了解这些!
  2. 链表:203.移除链表元素
  3. 链表:707.设计链表
  4. 链表:206.翻转链表
  5. 链表:24.两两交换链表中的节点
  6. 链表:19.删除链表的倒数第 N 个结点
  7. 链表:链表相交
  8. 链表:142.环形链表
  9. 链表:总结篇!
哈希表
  1. 关于哈希表,你该了解这些!
  2. 哈希表:242.有效的字母异位词
  3. 哈希表:1002.查找常用字符
  4. 哈希表:349.两个数组的交集
  5. 哈希表:202.快乐数
  6. 哈希表:1.两数之和
  7. 哈希表:454.四数相加II
  8. 哈希表:383.赎金信
  9. 哈希表:15.三数之和
  10. 双指针法:18.四数之和
  11. 哈希表:总结篇!
字符串
  1. 字符串:344.反转字符串
  2. 字符串:541.反转字符串II
  3. 字符串:替换数字
  4. 字符串:151.翻转字符串里的单词
  5. 字符串:右旋字符串
  6. 帮你把KMP算法学个通透
  7. 字符串:459.重复的子字符串
  8. 字符串:总结篇!
双指针法

双指针法基本都是应用在数组,字符串与链表的题目上

  1. 数组:27.移除元素
  2. 字符串:344.反转字符串
  3. 字符串:替换数字
  4. 字符串:151.翻转字符串里的单词
  5. 链表:206.翻转链表
  6. 链表:19.删除链表的倒数第 N 个结点
  7. 链表:链表相交
  8. 链表:142.环形链表
  9. 双指针:15.三数之和
  10. 双指针:18.四数之和
  11. 双指针:总结篇!
栈与队列
  1. 栈与队列:理论基础
  2. 栈与队列:232.用栈实现队列
  3. 栈与队列:225.用队列实现栈
  4. 栈与队列:20.有效的括号
  5. 栈与队列:1047.删除字符串中的所有相邻重复项
  6. 栈与队列:150.逆波兰表达式求值
  7. 栈与队列:239.滑动窗口最大值
  8. 栈与队列:347.前K个高频元素
  9. 栈与队列:总结篇!
二叉树

题目分类大纲如下: 二叉树大纲

  1. 关于二叉树,你该了解这些!
  2. 二叉树:二叉树的递归遍历
  3. 二叉树:二叉树的迭代遍历
  4. 二叉树:二叉树的统一迭代法
  5. 二叉树:二叉树的层序遍历
  6. 二叉树:226.翻转二叉树
  7. 本周小结!(二叉树)
  8. 二叉树:101.对称二叉树
  9. 二叉树:104.二叉树的最大深度
  10. 二叉树:111.二叉树的最小深度
  11. 二叉树:222.完全二叉树的节点个数
  12. 二叉树:110.平衡二叉树
  13. 二叉树:257.二叉树的所有路径
  14. 本周总结!(二叉树)
  15. 二叉树:404.左叶子之和
  16. 二叉树:513.找树左下角的值
  17. 二叉树:112.路径总和
  18. 二叉树:106.构造二叉树
  19. 二叉树:654.最大二叉树
  20. 本周小结!(二叉树)
  21. 二叉树:617.合并两个二叉树
  22. 二叉树:700.二叉搜索树登场!
  23. 二叉树:98.验证二叉搜索树
  24. 二叉树:530.搜索树的最小绝对差
  25. 二叉树:501.二叉搜索树中的众数
  26. 二叉树:236.公共祖先问题
  27. 本周小结!(二叉树)
  28. 二叉树:235.搜索树的最近公共祖先
  29. 二叉树:701.搜索树中的插入操作
  30. 二叉树:450.搜索树中的删除操作
  31. 二叉树:669.修剪二叉搜索树
  32. 二叉树:108.将有序数组转换为二叉搜索树
  33. 二叉树:538.把二叉搜索树转换为累加树
  34. 二叉树:总结篇!(需要掌握的二叉树技能都在这里了)
回溯算法

回溯算法大纲

  1. 关于回溯算法,你该了解这些!
  2. 回溯算法:77.组合
  3. 回溯算法:77.组合优化
  4. 回溯算法:216.组合总和III
  5. 回溯算法:17.电话号码的字母组合
  6. 本周小结!(回溯算法系列一)
  7. 回溯算法:39.组合总和
  8. 回溯算法:40.组合总和II
  9. 回溯算法:131.分割回文串
  10. 回溯算法:93.复原IP地址
  11. 回溯算法:78.子集
  12. 本周小结!(回溯算法系列二)
  13. 回溯算法:90.子集II
  14. 回溯算法:491.递增子序列
  15. 回溯算法:46.全排列
  16. 回溯算法:47.全排列II
  17. 本周小结!(回溯算法系列三)
  18. 回溯算法去重问题的另一种写法
  19. 回溯算法:332.重新安排行程
  20. 回溯算法:51.N皇后
  21. 回溯算法:37.解数独
  22. 回溯算法总结篇
贪心算法

贪心算法大纲

  1. 关于贪心算法,你该了解这些!
  2. 贪心算法:455.分发饼干
  3. 贪心算法:376.摆动序列
  4. 贪心算法:53.最大子序和
  5. 本周小结!(贪心算法系列一)
  6. 贪心算法:122.买卖股票的最佳时机II
  7. 贪心算法:55.跳跃游戏
  8. 贪心算法:45.跳跃游戏II
  9. 贪心算法:1005.K次取反后最大化的数组和
  10. 本周小结!(贪心算法系列二)
  11. 贪心算法:134.加油站
  12. 贪心算法:135.分发糖果
  13. 贪心算法:860.柠檬水找零
  14. 贪心算法:406.根据身高重建队列
  15. 本周小结!(贪心算法系列三)
  16. 贪心算法:406.根据身高重建队列(续集)
  17. 贪心算法:452.用最少数量的箭引爆气球
  18. 贪心算法:435.无重叠区间
  19. 贪心算法:763.划分字母区间
  20. 贪心算法:56.合并区间
  21. 本周小结!(贪心算法系列四)
  22. 贪心算法:738.单调递增的数字
  23. 贪心算法:968.监控二叉树
  24. 贪心算法:总结篇!(每逢总结必经典)
动态规划

动态规划专题已经开始啦,来不及解释了,小伙伴们上车别掉队!

  1. 关于动态规划,你该了解这些!
  2. 动态规划:509.斐波那契数
  3. 动态规划:70.爬楼梯
  4. 动态规划:746.使用最小花费爬楼梯
  5. 本周小结!(动态规划系列一)
  6. 动态规划:62.不同路径
  7. 动态规划:63.不同路径II
  8. 动态规划:343.整数拆分
  9. 动态规划:96.不同的二叉搜索树
  10. 本周小结!(动态规划系列二)

背包问题系列:

背包问题大纲

  1. 动态规划:01背包理论基础(二维dp数组)
  2. 动态规划:01背包理论基础(一维dp数组)
  3. 动态规划:416.分割等和子集
  4. 动态规划:1049.最后一块石头的重量II
  5. 本周小结!(动态规划系列三)
  6. 动态规划:494.目标和
  7. 动态规划:474.一和零
  8. 动态规划:完全背包理论基础(二维dp数组)
  9. 动态规划:完全背包理论基础(一维dp数组)
  10. 动态规划:518.零钱兑换II
  11. 本周小结!(动态规划系列四)
  12. 动态规划:377.组合总和Ⅳ
  13. 动态规划:70.爬楼梯(完全背包版本)
  14. 动态规划:322.零钱兑换
  15. 动态规划:279.完全平方数
  16. 本周小结!(动态规划系列五)
  17. 动态规划:139.单词拆分
  18. 动态规划:多重背包理论基础
  19. 背包问题总结篇

打家劫舍系列:

  1. 动态规划:198.打家劫舍
  2. 动态规划:213.打家劫舍II
  3. 动态规划:337.打家劫舍III

股票系列:

股票问题总结

  1. 动态规划:121.买卖股票的最佳时机
  2. 动态规划:本周小结(系列六)
  3. 动态规划:122.买卖股票的最佳时机II
  4. 动态规划:123.买卖股票的最佳时机III
  5. 动态规划:188.买卖股票的最佳时机IV
  6. 动态规划:309.最佳买卖股票时机含冷冻期
  7. 动态规划:本周小结(系列七)
  8. 动态规划:714.买卖股票的最佳时机含手续费
  9. 动态规划:股票系列总结篇

子序列系列:

  1. 动态规划:300.最长递增子序列
  2. 动态规划:674.最长连续递增序列
  3. 动态规划:718.最长重复子数组
  4. 动态规划:1143.最长公共子序列
  5. 动态规划:1035.不相交的线
  6. 动态规划:53.最大子序和
  7. 动态规划:392.判断子序列
  8. 动态规划:115.不同的子序列
  9. 动态规划:583.两个字符串的删除操作
  10. 动态规划:72.编辑距离
  11. 编辑距离总结篇
  12. 动态规划:647.回文子串
  13. 动态规划:516.最长回文子序列
  14. 动态规划总结篇
单调栈
  1. 单调栈:739.每日温度
  2. 单调栈:496.下一个更大元素I
  3. 单调栈:503.下一个更大元素II
  4. 单调栈:42.接雨水
  5. 单调栈:84.柱状图中最大的矩形
图论

图论正式发布

  1. 图论:理论基础
  2. 图论:深度优先搜索理论基础
  3. 图论:所有可达路径
  4. 图论:广度优先搜索理论基础
  5. 图论:岛屿数量.深搜版
  6. 图论:岛屿数量.广搜版
  7. 图论:岛屿的最大面积
  8. 图论:孤岛的总面积
  9. 图论:沉没孤岛
  10. 图论:水流问题
  11. 图论:建造最大岛屿
  12. 图论:岛屿的周长
  13. 图论:字符串接龙
  14. 图论:有向图的完全可达性
  15. 图论:并查集理论基础
  16. 图论:寻找存在的路径
  17. 图论:冗余连接
  18. 图论:冗余连接II
  19. 图论:最小生成树之prim
  20. 图论:最小生成树之kruskal
  21. 图论:拓扑排序
  22. 图论:dijkstra(朴素版)
  23. 图论:dijkstra(堆优化版)
  24. 图论:Bellman_ford 算法
  25. 图论:Bellman_ford 队列优化算法(又名SPFA)
  26. 图论:Bellman_ford之判断负权回路
  27. 图论:Bellman_ford之单源有限最短路
  28. 图论:Floyd 算法
  29. 图论:A * 算法
  30. 图论:最短路算法总结篇
  31. 图论:图论总结篇

🧩 算法模板


🙌 参与贡献

  • 欢迎提交 **题解修订 / 多语言实现 / 文档勘误 / 新增练习**
  • 请先阅读:如何提交与协作
  • 致谢所有贡献者 → Contributors

⭐ Star 趋势

Star History Chart


👨‍💻 关于作者

大家好,我是 程序员 Carl,哈工大师兄,先后在腾讯、百度从事后端与底层技术研发,著有《代码随想录》。


📥 PDF 下载与学习群

添加下方企业微信,自动获取 PDF 精讲,并可选择加入刷题群:

备注格式

  • 在职:姓名-城市-岗位
  • 学生:姓名-学校-年级(无备注不通过)


📜 版权说明

  • 本仓库所有内容均为原创,引用需 **注明出处与链接**。
  • 严禁恶意搬运与洗稿,侵权必究。