Top Related Projects
LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)
Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)
✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
Solutions to LeetCode problems; updated daily. Subscribe to my YouTube channel for more.
🏋️ Python / Modern C++ Solutions of All 3283 LeetCode Problems (Weekly Update)
Quick Overview
The pezy/LeetCode repository is a collection of LeetCode problem solutions implemented in C++. It serves as a resource for developers preparing for coding interviews or improving their algorithmic skills. The repository contains a wide range of problems from various difficulty levels, providing comprehensive coverage of LeetCode challenges.
Pros
- Extensive collection of LeetCode solutions in C++
- Well-organized structure with solutions categorized by problem number
- Includes detailed comments and explanations for many solutions
- Regularly updated with new problem solutions
Cons
- Primarily focuses on C++ implementations, limiting usefulness for developers using other languages
- Some solutions may lack detailed explanations or alternative approaches
- Not all LeetCode problems are covered, though the collection is substantial
- May encourage direct copying of solutions rather than independent problem-solving
Code Examples
Here are a few examples of solutions from the repository:
- Two Sum problem (Problem 1):
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.count(complement))
return {map[complement], i};
map[nums[i]] = i;
}
return {};
}
};
This solution uses a hash map to efficiently find the complement of each number.
- Add Two Numbers problem (Problem 2):
class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
ListNode dummy(0);
ListNode* curr = &dummy;
int carry = 0;
while (l1 || l2 || carry) {
int sum = (l1 ? l1->val : 0) + (l2 ? l2->val : 0) + carry;
carry = sum / 10;
curr->next = new ListNode(sum % 10);
curr = curr->next;
l1 = l1 ? l1->next : nullptr;
l2 = l2 ? l2->next : nullptr;
}
return dummy.next;
}
};
This solution adds two numbers represented as linked lists, handling carry and different list lengths.
Getting Started
To use these solutions:
-
Clone the repository:
git clone https://github.com/pezy/LeetCode.git
-
Navigate to the specific problem's directory:
cd LeetCode/algorithms
-
Open the desired solution file (e.g.,
001.two-sum.cpp
) in your preferred C++ IDE or text editor. -
Compile and run the code to test the solution:
g++ -std=c++11 001.two-sum.cpp -o solution ./solution
Note: Make sure you have a C++11 compatible compiler installed on your system.
Competitor Comparisons
LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)
Pros of leetcode
- More comprehensive coverage with solutions in multiple languages (JavaScript, Python, C++, Java)
- Includes detailed explanations and analysis for many problems
- Actively maintained with frequent updates and contributions
Cons of leetcode
- Less organized structure compared to LeetCode's clear categorization
- May be overwhelming for beginners due to the large volume of content
- Some solutions lack consistency in coding style and documentation
Code Comparison
LeetCode (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) {
if (map.count(target - nums[i])) return {map[target - nums[i]], i};
map[nums[i]] = i;
}
return {};
}
};
leetcode (JavaScript):
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 solutions to LeetCode problems, but leetcode offers a wider range of languages and more detailed explanations. LeetCode maintains a cleaner structure, while leetcode provides a more extensive collection of solutions and discussions.
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
- Includes solutions in multiple programming languages
Cons of LeetCodeAnimation
- Less comprehensive coverage of LeetCode problems compared to LeetCode
- Animations may not be as helpful for experienced programmers who prefer concise code solutions
- Updates less frequently than LeetCode
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.count(target - nums[i])) return {map[target - nums[i]], i};
map[nums[i]] = i;
}
return {};
}
LeetCodeAnimation (JavaScript solution for Two Sum):
var twoSum = function(nums, target) {
const map = new Map();
for (let i = 0; i < nums.length; i++) {
if (map.has(target - nums[i])) return [map.get(target - nums[i]), i];
map.set(nums[i], i);
}
};
Both repositories offer valuable resources for LeetCode problem-solving. LeetCode provides a more extensive collection of solutions in C++, while LeetCodeAnimation offers visual aids and multi-language support. The choice between them depends on individual learning preferences and programming language requirements.
✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
Pros of LeetCode-Go
- Written in Go, offering solutions for those learning or working with Golang
- More comprehensive, with solutions for 700+ LeetCode problems
- Includes detailed explanations and time/space complexity analyses for each solution
Cons of LeetCode-Go
- Limited to a single programming language (Go)
- May be less accessible for beginners due to its focus on a less common language for coding interviews
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.count(target - nums[i]))
return {m[target - nums[i]], i};
m[nums[i]] = i;
}
return {};
}
Both implementations solve the "Two Sum" problem efficiently, but LeetCode-Go uses Go-specific syntax and features, while LeetCode uses C++. The overall logic remains similar, demonstrating the repositories' focus on their respective languages.
Solutions to LeetCode problems; updated daily. Subscribe to my YouTube channel for more.
Pros of Leetcode
- More comprehensive coverage with 1000+ solutions
- Solutions provided in multiple programming languages (Java, Python, C++)
- Includes detailed explanations and time/space complexity analysis for many problems
Cons of Leetcode
- Less frequent updates compared to LeetCode
- Repository structure is more complex, potentially making navigation harder
- Some solutions lack detailed explanations or comments
Code Comparison
LeetCode (C++):
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> mapping;
vector<int> result;
for (int i = 0; i < nums.size(); ++i) {
if (mapping.find(target - nums[i]) != mapping.end()) {
result.push_back(mapping[target - nums[i]]);
result.push_back(i);
return result;
}
mapping[nums[i]] = i;
}
return result;
}
};
Leetcode (Java):
public 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 solutions implement the Two Sum problem efficiently using hash maps, but the Leetcode solution provides implementations in multiple languages.
🏋️ Python / Modern C++ Solutions of All 3283 LeetCode Problems (Weekly Update)
Pros of LeetCode-Solutions
- More comprehensive coverage with solutions for 1900+ problems
- Includes solutions in multiple programming languages (C++, Python, Java)
- Regularly updated with new problem solutions
Cons of LeetCode-Solutions
- Less detailed explanations for each solution
- Code style and formatting may be less consistent across solutions
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> mapping;
vector<int> result;
for (int i = 0; i < nums.size(); ++i) {
if (mapping.find(target - nums[i]) != mapping.end()) {
result.push_back(mapping[target - nums[i]]);
result.push_back(i);
return result;
}
mapping[nums[i]] = i;
}
return result;
}
};
Both repositories provide solutions to LeetCode problems, but LeetCode-Solutions offers a wider range of problems and languages. However, LeetCode may provide more detailed explanations and consistent coding style. 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 solutions in C++ 11 and Python3.
Top Related Projects
LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)
Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)
✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
Solutions to LeetCode problems; updated daily. Subscribe to my YouTube channel for more.
🏋️ 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