Convert Figma logo to code with AI

labuladong logofucking-algorithm

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

124,927
23,183
124,927
40

Top Related Projects

《Hello 算法》:动画图解、一键运行的数据结构与算法教程。支持 Python, Java, C++, C, C#, JS, Go, Swift, Rust, Ruby, Kotlin, TS, Dart 代码。简体版和繁体版同步更新,English version ongoing

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

54,397

LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)

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

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

174,630

:books: 技术面试必备基础知识、Leetcode、计算机操作系统、计算机网络、系统设计

Quick Overview

The "fucking-algorithm" repository on GitHub, created by labuladong, is a comprehensive collection of algorithms and data structures, accompanied by detailed explanations and solutions to common coding problems. The repository serves as a valuable resource for developers, students, and anyone interested in improving their problem-solving skills and expanding their algorithmic knowledge.

Pros

  • Comprehensive Coverage: The repository covers a wide range of algorithmic topics, including dynamic programming, greedy algorithms, graph theory, and more, making it a one-stop-shop for algorithm learning.
  • Detailed Explanations: The author, labuladong, provides in-depth explanations and step-by-step solutions for each problem, making it easier for users to understand the underlying concepts and approaches.
  • Practical Applications: The problems and solutions presented in the repository are often drawn from real-world scenarios, making the content more relevant and applicable to everyday programming tasks.
  • Active Community: The repository has a large and active community of contributors and users, who provide feedback, suggestions, and additional solutions, further enhancing the project's value.

Cons

  • Language Specific: The repository is primarily focused on algorithms and solutions in the Python and Java programming languages, which may limit its usefulness for developers working in other languages.
  • Lack of Structured Curriculum: While the repository covers a wide range of topics, it may lack a structured curriculum or learning path, which could make it challenging for beginners to navigate and progress through the content.
  • Potential Outdated Content: As with any open-source project, there is a possibility that some of the content in the repository may become outdated over time, requiring regular updates and maintenance.
  • Overwhelming for Beginners: The sheer volume of content and the complexity of some of the algorithms presented in the repository may be overwhelming for beginners, who may benefit from a more gradual and structured approach to learning.

Code Examples

Here are a few short code examples from the "fucking-algorithm" repository:

  1. Reversing a Linked List:
def reverseList(head: ListNode) -> ListNode:
    prev, curr = None, head
    while curr:
        next_node = curr.next
        curr.next = prev
        prev = curr
        curr = next_node
    return prev

This code demonstrates the implementation of the "Reverse Linked List" problem, where the goal is to reverse the order of the nodes in a singly-linked list.

  1. Climbing Stairs:
public int climbStairs(int n) {
    if (n <= 2) {
        return n;
    }
    int[] dp = new int[n + 1];
    dp[1] = 1;
    dp[2] = 2;
    for (int i = 3; i <= n; i++) {
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    return dp[n];
}

This code demonstrates the implementation of the "Climbing Stairs" problem, where the goal is to find the number of unique ways to climb to the top of a staircase with n steps, given that you can either take 1 step or 2 steps at a time.

  1. Merge Two Sorted Lists:
def mergeTwoLists(l1: ListNode, l2: ListNode) -> ListNode:
    dummy = ListNode()
    curr = dummy
    while l1 and l2:
        if l1.val < l2.val:
            curr.next = l1
            l1 = l1.next
        else:
            curr.next = l2
            l2 = l2.next
        curr = curr.next
    if l1:
        curr.next = l1
    if l2:
        curr.next = l2
    return dummy.next

This code demonstrates the implementation of the "Merge Two Sorted Lists" problem, where the goal is to merge two sorted linked lists into a single sorted linked list.

Getting Started

To get started with the "fucking-algorithm" repository, follow these steps:

  1. Clone the repository to your local machine:
git clone https://github.com/labuladong/fucking-algorithm.git
  1. Navigate

Competitor Comparisons

《Hello 算法》:动画图解、一键运行的数据结构与算法教程。支持 Python, Java, C++, C, C#, JS, Go, Swift, Rust, Ruby, Kotlin, TS, Dart 代码。简体版和繁体版同步更新,English version ongoing

Pros of hello-algo

  • Offers implementations in multiple programming languages (C, C++, Java, Python, etc.)
  • Provides interactive visualizations for algorithms and data structures
  • Includes a comprehensive e-book with detailed explanations

Cons of hello-algo

  • Less extensive coverage of advanced algorithms compared to fucking-algorithm
  • Newer project with potentially fewer community contributions and discussions
  • May lack some of the in-depth problem-solving strategies found in fucking-algorithm

Code Comparison

hello-algo (Python):

def binary_search(nums: List[int], target: int) -> int:
    left, right = 0, len(nums) - 1
    while left <= right:
        mid = (left + right) // 2
        if nums[mid] < target:
            left = mid + 1
        elif nums[mid] > target:
            right = mid - 1
        else:
            return mid
    return -1

fucking-algorithm (Java):

int binarySearch(int[] nums, int target) {
    int left = 0, right = nums.length - 1;
    while(left <= right) {
        int mid = left + (right - left) / 2;
        if (nums[mid] == target)
            return mid;
        else if (nums[mid] < target)
            left = mid + 1;
        else if (nums[mid] > target)
            right = mid - 1;
    }
    return -1;
}

Both repositories provide excellent resources for learning algorithms and data structures. hello-algo offers a more visual and interactive approach with multi-language support, while fucking-algorithm provides a deeper dive into problem-solving techniques and advanced algorithms.

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

Pros of leetcode-master

  • More comprehensive coverage of LeetCode problems, with over 300 solutions
  • Includes detailed explanations and diagrams for complex algorithms
  • Regularly updated with new problems and solutions

Cons of leetcode-master

  • Primarily focused on C++ solutions, which may not be ideal for all users
  • Less emphasis on general problem-solving strategies compared to fucking-algorithm

Code Comparison

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 {};
    }
};

fucking-algorithm (Java):

class Solution {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int complement = target - nums[i];
            if (map.containsKey(complement)) {
                return new int[] { map.get(complement), i };
            }
            map.put(nums[i], i);
        }
        throw new IllegalArgumentException("No two sum solution");
    }
}

Both repositories offer valuable resources for learning algorithms and solving LeetCode problems. leetcode-master provides a more extensive collection of problems and solutions, while fucking-algorithm focuses on teaching problem-solving strategies and techniques. The choice between the two depends on the user's preferred programming language and learning style.

54,397

LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)

Pros of leetcode

  • Covers a wider range of LeetCode problems, providing solutions in multiple programming languages
  • Includes detailed explanations and time/space complexity analyses for each solution
  • Offers a more comprehensive approach to LeetCode preparation, including company-specific problem lists

Cons of leetcode

  • Less focus on algorithmic patterns and problem-solving techniques compared to fucking-algorithm
  • May be overwhelming for beginners due to the sheer volume of problems and solutions
  • Lacks the structured learning path and in-depth explanations found in fucking-algorithm

Code Comparison

fucking-algorithm (Java):

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

leetcode (JavaScript):

var reverseList = function(head) {
    let prev = null, curr = head;
    while (curr) {
        [curr.next, prev, curr] = [prev, curr, curr.next];
    }
    return prev;
};

Both repositories provide solutions to common LeetCode problems, but they differ in their approach and focus. fucking-algorithm emphasizes understanding algorithmic patterns and problem-solving techniques, while leetcode offers a broader range of problems and solutions in multiple languages. The code comparison shows similar implementations of reversing a linked list, with fucking-algorithm using a more traditional approach in Java and leetcode showcasing a concise ES6 solution in JavaScript.

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

Pros of LeetCode-Go

  • Focuses specifically on Go language implementations
  • Includes detailed explanations and comments in the code
  • Covers a wide range of LeetCode problems with consistent structure

Cons of LeetCode-Go

  • Limited to Go language, less accessible for users of other languages
  • May not provide as in-depth algorithmic explanations as fucking-algorithm

Code Comparison

LeetCode-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
}

fucking-algorithm:

public int[] twoSum(int[] nums, int target) {
    Map<Integer, Integer> map = new HashMap<>();
    for (int i = 0; i < nums.length; i++) {
        int complement = target - nums[i];
        if (map.containsKey(complement)) {
            return new int[] { map.get(complement), i };
        }
        map.put(nums[i], i);
    }
    throw new IllegalArgumentException("No two sum solution");
}

Both repositories provide high-quality algorithm implementations and explanations, but they cater to different audiences. LeetCode-Go is ideal for Go developers looking for language-specific solutions, while fucking-algorithm offers a more language-agnostic approach with in-depth algorithmic insights.

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

Pros of LeetCodeAnimation

  • Utilizes animations and visual aids to explain algorithms, making complex concepts easier to understand
  • Covers a wide range of LeetCode problems, providing solutions for various difficulty levels
  • Includes explanations in both Chinese and English, making it accessible to a broader audience

Cons of LeetCodeAnimation

  • Less comprehensive in terms of algorithm theory and problem-solving strategies
  • Animations may not be as effective for learners who prefer text-based explanations
  • Updates are less frequent compared to fucking-algorithm

Code Comparison

LeetCodeAnimation:

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

fucking-algorithm:

ListNode* reverseList(ListNode* head) {
    if (head == nullptr || head->next == nullptr) {
        return head;
    }
    ListNode* last = reverseList(head->next);
    head->next->next = head;
    head->next = nullptr;
    return last;
}

Both repositories offer valuable resources for learning algorithms and solving LeetCode problems. LeetCodeAnimation excels in visual explanations, while fucking-algorithm provides more in-depth theoretical knowledge and problem-solving techniques.

174,630

:books: 技术面试必备基础知识、Leetcode、计算机操作系统、计算机网络、系统设计

Pros of CS-Notes

  • Broader coverage of computer science topics, including operating systems, networks, and databases
  • More comprehensive preparation for technical interviews and coding tests
  • Includes system design concepts, which are crucial for senior-level positions

Cons of CS-Notes

  • Less focus on in-depth algorithm explanations and problem-solving strategies
  • May be overwhelming for beginners due to the vast amount of information covered
  • Lacks the engaging narrative style found in fucking-algorithm

Code Comparison

CS-Notes example (Java):

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

fucking-algorithm example (Python):

def reverseList(self, head: ListNode) -> ListNode:
    prev, curr = None, head
    while curr:
        curr.next, prev, curr = prev, curr, curr.next
    return prev

Both repositories offer valuable resources for learning algorithms and data structures. CS-Notes provides a more comprehensive overview of computer science topics, making it suitable for interview preparation and general knowledge. fucking-algorithm focuses more on in-depth algorithm explanations and problem-solving techniques, which can be particularly helpful for mastering specific algorithms and improving coding skills.

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

English version repo and Gitbook is on english branch. Just enjoy:)

labuladong 的算法小抄

Website GitHub

好消息,2023 最新版《labuladong 的算法笔记》纸质书出版啦!微信扫码查看简介👆

Star History Chart

本仓库总共 60 多篇原创文章,都是基于 LeetCode 的题目,涵盖了所有题型和技巧,而且一定要做到举一反三,通俗易懂,绝不是简单的代码堆砌,后面有目录。

我先吐槽几句。**刷题刷题,刷的是题,培养的是思维,本仓库的目的就是传递这种算法思维**。我要是只写一个包含 LeetCode 题目代码的仓库,有个锤子用?没有思路解释,没有思维框架,顶多写个时间复杂度,那玩意一眼就能看出来。

只想要答案的话很容易,题目评论区五花八门的答案,动不动就秀 python 一行代码解决,有那么多人点赞。问题是,你去做算法题,是去学习编程语言的奇技淫巧的,还是学习算法思维的呢?你的快乐,到底源自复制别人的一行代码通过测试,已完成题目 +1,还是源自自己通过逻辑推理和算法框架不看答案写出解法?

网上总有大佬喷我,说我写的东西太基础,要么说不能借助框架思维来学习算法。我只能说大家刷算法就是找工作吃饭的,不是打竞赛的,我也是一路摸爬滚打过来的,我们要的是清楚明白有所得,不是故弄玄虚无所指。

不想办法做到通俗易懂,难道要上来先把《算法导论》吹上天,然后把人家都心怀敬仰地劝退?

**做啥事情做多了,都能发现套路的,我把各种算法套路框架总结出来,相信可以帮助其他人少走弯路**。我这个纯靠自学的小童鞋,花了一年时间刷题和总结,自己写了一份算法小抄,后面有目录,这里就不废话了。

在开始学习之前

1、先给本仓库点个 star,满足一下我的虚荣心,文章质量绝对值你一个 star。我还在继续创作,给我一点继续写文的动力,感谢。

2、建议关注我的公众号 labuladong,坚持高质量原创,说是最良心最硬核的技术公众号都不为过。本仓库的文章就是从公众号里整理出来的一部分内容,公众号可以查看更多内容:

**3、建议收藏我的在线网站,每篇文章开头都有对应的力扣题目链接,可以边看文章边刷题,一共可以手把手带你刷 300 道题目**:

GitHub Pages 地址:https://labuladong.online/algo/

Gitee Pages 地址:https://labuladong.gitee.io/algo/

2024 最新地址:https://labuladong.online/algo/

**另外建议关注 我的 B 站,我把一系列核心算法技巧的文章都录制成了领读视频,方便大家学习**。

安装使用 labuladong 的刷题全家桶

tip:labuladong 的刷题全家桶由学习网站、《算法秘籍》《刷题笔记》两本 PDF、Chrome/vscode/Jetbrain 三个不同平台的刷题插件组成,致力于为大家提供最丝滑的刷题体验。公众号后台回复关键词「**全家桶**」即可获取下载和使用手册。

一、公众号/学习网站

内容当然是我的系列算法教程中最核心的部分,其他的插件和 PDF 教材都是为内容服务的。我的算法教程都发布在公众号/网站上,相信你会未来会在这里花费大量的学习时间,而不是仅仅加入收藏夹~

具体介绍:labuladong 的公众号/算法网站使用手册

二、PDF 教材

鉴于我积累的算法教程比较多,为了防止过于陡峭的学习曲线,我精心挑选了必知必会的算法技巧,设计了一套循序渐进的学习路线,并制作成 PDF 方便大家离线学习/记笔记。

PDF 共两本,一本《labuladong 的算法秘籍》类似教材,帮你系统掌握算法的知识体系:

另一本《labuladong 的刷题笔记》类似练习册,助你遨游题海,随心所欲地运用所学的技巧解题:

具体介绍:配套 PDF 算法教材使用手册

三、精品课程

如果你认可我的算法教程,可以购买我的付费课程,目前我制作完成了《数据结构精品课》 和《二叉树(递归)专题课》。另外,还有押金形式的刷题打卡挑战,完成打卡后押金将全额返还,打卡挑战适用于自己刷题坚持不下来的小伙伴参加。

课程和打卡挑战都可以在我的知识店铺购买和报名:

话说回来,我今天能拥有这么多读者,都靠大家捧场,大家能从我这学到东西我就很高兴,不差钱的买个课捧个钱场,缺钱的把我的公众号/网站推荐给身边的朋友捧个人场,都是对我的支持!

四、Chrome 插件

主要功能:Chrome 插件可以在中文版力扣或英文版 LeetCode 上快捷查看我的「题解」或「思路」,并添加了题目和算法技巧之间的引用关系,可以和我的网站/公众号/课程联动,给我的读者提供最丝滑的刷题体验。

安装使用手册:Chrome 插件安装使用手册

五、vscode 插件

主要功能:和 Chrome 插件功能基本相同,习惯在 vscode 上刷题的读者可以使用该插件。

安装使用手册:vscode 插件安装使用手册

六、Jetbrains 插件

主要功能:和 Chrome 插件功能基本相同,习惯在 Jetbrains 家的 IDE(PyCharm/Intellij/Goland 等)上刷题的读者可以使用该插件。

安装使用手册:Jetbrains 插件安装使用手册

最后,把上面这些工具汇总成一张图:

祝大家学习愉快,在题海中自在遨游!

文章目录

本站简介

准备工作:安装刷题全家桶

极速入门:数据结构基础

第零章、核心框架汇总

第一章、手把手刷数据结构

第二章、手把手刷动态规划

第三章、必知必会算法技巧

感谢如下大佬参与翻译

按照昵称字典序排名:

ABCpril, andavid, bryceustc, build2645, CarrieOn, cooker, Dong Wang, ExcaliburEX, floatLig, ForeverSolar, Fulin Li, Funnyyanne, GYHHAHA, Hi_archer, Iruze, Jieyixia, Justin, Kevin, Lrc123, lriy, Lyjeeq, MasonShu, Master-cai, miaoxiaozui2017, natsunoyoru97, nettee, PaperJets, qy-yang, realism0331, SCUhzs, Seaworth, shazi4399, ShuozheLi, sinjoywong, sunqiuming526, Tianhao Zhou, timmmGZ, tommytim0515, ucsk, wadegrc, walsvid, warmingkkk, Wonderxie, wsyzxxxx, xiaodp, youyun, yx-tan, Zero, Ziming

Donate

如果本仓库对你有帮助,可以请作者喝杯速溶咖啡