Convert Figma logo to code with AI

labuladong logofucking-algorithm

Crack LeetCode, not only how, but also why.

133,114
23,689
133,114
0

Top Related Projects

123,749

《Hello 算法》:动画图解、一键运行的数据结构与算法教程。支持简中、繁中、English、日本語,提供 Python, Java, C++, C, C#, JS, Go, Swift, Rust, Ruby, Kotlin, TS, Dart 等代码实现

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

55,814

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题目的思路)

183,999

: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

123,749

《Hello 算法》:动画图解、一键运行的数据结构与算法教程。支持简中、繁中、English、日本語,提供 Python, Java, C++, C, C#, JS, Go, Swift, Rust, Ruby, Kotlin, TS, Dart 等代码实现

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.

55,814

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.

183,999

: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

Star History Chart

labuladong Algo Notes

This repository contains 60+ original articles based on LeetCode problems, covering all problem types and techniques. The goal is to help you think algorithmically — not just memorize solutions.

When it comes to LeetCode, what matters is not the answer itself, but the thought process behind it. A repository full of raw code without explanation isn't very useful. The real value lies in understanding the frameworks and patterns that let you solve new problems on your own.

Most people grind LeetCode to land a job, not to compete in programming contests. So the focus here is on clarity and practical understanding — building reusable mental frameworks that make algorithm problems approachable and solvable.

Before You Start

1. Give this repo a star if you find it helpful — it keeps me motivated to write more.

2. I recommend studying on my website, where each article links to the corresponding LeetCode problems so you can read and practice side by side. The site covers 500+ problems with step-by-step guidance:

https://labuladong.online/en/algo/

Table of Contents