Top Related Projects
Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)
LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)
刷算法全靠套路,认准 labuladong 就够了!English version supported! Crack LeetCode, not only how, but also why.
✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
Everything you need to know to get the job.
🏋️ Python / Modern C++ Solutions of All 3283 LeetCode Problems (Weekly Update)
Quick Overview
The haoel/leetcode repository is a collection of LeetCode problem solutions implemented in various programming languages, primarily C++. It serves as a resource for developers preparing for coding interviews or looking to improve their problem-solving skills. The repository includes solutions to a wide range of algorithmic and data structure problems.
Pros
- Comprehensive collection of LeetCode problem solutions
- Solutions are implemented in multiple programming languages, with a focus on C++
- Well-organized structure with problems categorized by difficulty and topic
- Includes explanations and comments for many solutions, aiding in understanding
Cons
- Some solutions may not be optimized or represent the best approach
- Not all problems have solutions in every programming language
- Limited community engagement and contributions
- May not always be up-to-date with the latest LeetCode problems
Code Examples
Here are a few examples of problem solutions from the repository:
- Two Sum problem (Easy):
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> map;
for (int i = 0; i < nums.size(); i++) {
int complement = target - nums[i];
if (map.find(complement) != map.end()) {
return {map[complement], i};
}
map[nums[i]] = i;
}
return {};
}
};
- Reverse Linked List (Easy):
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* prev = nullptr;
ListNode* curr = head;
while (curr != nullptr) {
ListNode* nextTemp = curr->next;
curr->next = prev;
prev = curr;
curr = nextTemp;
}
return prev;
}
};
- Valid Parentheses (Easy):
class Solution {
public:
bool isValid(string s) {
stack<char> st;
for (char c : s) {
if (c == '(' || c == '{' || c == '[') {
st.push(c);
} else {
if (st.empty()) return false;
if (c == ')' && st.top() != '(') return false;
if (c == '}' && st.top() != '{') return false;
if (c == ']' && st.top() != '[') return false;
st.pop();
}
}
return st.empty();
}
};
Getting Started
To use this repository:
- Clone the repository:
git clone https://github.com/haoel/leetcode.git
- Navigate to the problem you're interested in.
- Choose the programming language implementation you prefer.
- Study the solution and try to understand the approach.
- Implement and test the solution on LeetCode to verify its correctness.
Competitor Comparisons
Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)
Pros of LeetCodeAnimation
- Provides animated visualizations of algorithms, making them easier to understand
- Covers a wide range of LeetCode problems with detailed explanations
- Regularly updated with new content and improvements
Cons of LeetCodeAnimation
- Primarily focuses on Java solutions, limiting language diversity
- May not cover as many problems as leetcode repository
- Animations can be time-consuming to create, potentially slowing down updates
Code Comparison
LeetCodeAnimation (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;
}
leetcode (C++):
ListNode* reverseList(ListNode* head) {
ListNode* prev = nullptr;
ListNode* curr = head;
while (curr != nullptr) {
ListNode* nextTemp = curr->next;
curr->next = prev;
prev = curr;
curr = nextTemp;
}
return prev;
}
Both repositories provide solutions to the "Reverse Linked List" problem, but LeetCodeAnimation offers an animated explanation alongside the code, while leetcode focuses on concise implementations in multiple languages.
LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)
Pros of leetcode (azl397985856)
- More comprehensive coverage with 1000+ problems solved
- Includes detailed explanations and multiple solution approaches
- Actively maintained with frequent updates
Cons of leetcode (azl397985856)
- Primarily in Chinese, which may be a barrier for non-Chinese speakers
- Less organized structure compared to haoel's repository
- Some solutions may be overly complex for beginners
Code Comparison
leetcode (haoel):
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> m;
for (int i = 0; i < nums.size(); i++) {
if (m.find(target - nums[i]) != m.end()) {
return {m[target - nums[i]], i};
}
m[nums[i]] = i;
}
return {};
}
};
leetcode (azl397985856):
var twoSum = function(nums, target) {
const map = new Map();
for(let i = 0; i < nums.length; i++) {
const complement = target - nums[i];
if(map.has(complement)) {
return [map.get(complement), i];
}
map.set(nums[i], i);
}
};
Both repositories provide similar solutions, but in different programming languages. The azl397985856 repository often includes multiple approaches and more detailed explanations for each problem.
刷算法全靠套路,认准 labuladong 就够了!English version supported! Crack LeetCode, not only how, but also why.
Pros of fucking-algorithm
- Provides in-depth explanations and strategies for solving algorithmic problems
- Offers a structured learning approach with categorized topics
- Includes visualizations and diagrams to aid understanding
Cons of fucking-algorithm
- Limited to specific algorithms and problem-solving techniques
- May not cover as wide a range of LeetCode problems as leetcode
- Content is primarily in Chinese, which may be a barrier for non-Chinese speakers
Code Comparison
leetcode:
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> map;
for (int i = 0; i < nums.size(); i++) {
int complement = target - nums[i];
if (map.find(complement) != map.end()) {
return {map[complement], i};
}
map[nums[i]] = i;
}
return {};
}
};
fucking-algorithm:
def twoSum(nums: List[int], target: int) -> List[int]:
need = {}
for i, num in enumerate(nums):
if num in need:
return [need[num], i]
need[target - num] = i
return []
The code comparison shows different implementations of the "Two Sum" problem. leetcode uses C++ with an unordered_map, while fucking-algorithm uses Python with a dictionary. Both solutions have similar time complexity, but the Python implementation is more concise.
✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
Pros of LeetCode-Go
- Written in Go, offering solutions for those focusing on this language
- More comprehensive, with solutions for 700+ problems
- Includes detailed explanations and time/space complexity analyses
Cons of LeetCode-Go
- Limited to a single programming language (Go)
- May be overwhelming for beginners due to its extensive coverage
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 (C++):
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> m;
for (int i = 0; i < nums.size(); i++) {
if (m.find(target - nums[i]) != m.end()) {
return {m[target - nums[i]], i};
}
m[nums[i]] = i;
}
return {};
}
Both implementations solve the "Two Sum" problem efficiently using hash maps, but LeetCode-Go uses Go-specific syntax and features, while leetcode uses C++.
Everything you need to know to get the job.
Pros of interviews
- More comprehensive coverage of topics beyond just LeetCode problems
- Includes system design and behavioral interview preparation materials
- Provides additional resources like books, articles, and interview experiences
Cons of interviews
- Less focused on specific LeetCode problem solutions
- May not be as frequently updated as leetcode repository
- Organization can be more complex, potentially making it harder to find specific problems
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:
ListNode* reverseList(ListNode* head) {
ListNode* prev = nullptr;
while (head) {
ListNode* next = head->next;
head->next = prev;
prev = head;
head = next;
}
return prev;
}
Both repositories provide similar implementations for reversing a linked list, with interviews using Java and leetcode using C++. The logic and structure are nearly identical, demonstrating the consistency in problem-solving approaches across different programming languages.
🏋️ Python / Modern C++ Solutions of All 3283 LeetCode Problems (Weekly Update)
Pros of LeetCode-Solutions
- More comprehensive coverage with solutions in multiple programming languages
- Regularly updated with new problems and solutions
- Includes detailed explanations and time/space complexity analysis for each solution
Cons of LeetCode-Solutions
- Less organized structure compared to leetcode's categorization by difficulty
- May be overwhelming for beginners due to the sheer volume of solutions
- Some solutions lack detailed comments or explanations within the code
Code Comparison
LeetCode-Solutions (Python):
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
num_map = {}
for i, num in enumerate(nums):
if target - num in num_map:
return [num_map[target - num], i]
num_map[num] = i
return []
leetcode (C++):
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> m;
for (int i = 0; i < nums.size(); ++i) {
if (m.find(target - nums[i]) != m.end()) {
return {m[target - nums[i]], i};
}
m[nums[i]] = i;
}
return {};
}
};
Both repositories provide solutions to LeetCode problems, but LeetCode-Solutions offers a wider range of languages and more frequent updates. However, leetcode's organization may be more beginner-friendly. The code comparison shows similar approaches to the "Two Sum" problem, with LeetCode-Solutions using Python and leetcode using C++.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
LeetCode
LeetCode Algorithm
(Notes: "ð" means you need to buy a book from Leetcode)
LeetCode Shell
# | Title | Solution | Difficulty |
---|---|---|---|
4 | Tenth Line | Bash | Easy |
3 | Transpose File | Bash | Medium |
2 | Valid Phone Numbers | Bash | Easy |
1 | Word Frequency | Bash | Medium |
LintCode
# | Title | Solution | Difficulty |
---|---|---|---|
1 | Search in a big sorted array | Java | Medium |
2 | Search Range in Binary Search Tree | Java | Medium |
Top Related Projects
Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)
LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)
刷算法全靠套路,认准 labuladong 就够了!English version supported! Crack LeetCode, not only how, but also why.
✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
Everything you need to know to get the job.
🏋️ Python / Modern C++ Solutions of All 3283 LeetCode Problems (Weekly Update)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot