A curated repository of optimized solutions for LeetCode challenges implemented in C++ and Java. This repository serves as a reference for algorithmic problem solving, interview preparation, and mastering data structures.
LeetCode-Solutions is a collection of well-documented, efficient, and clean code solutions to a wide array of LeetCode problems. Each solution is accompanied by explanations that highlight the approach, complexity analysis, and any relevant edge cases. The main focus is on providing clear, modular code written in C++ and Java to facilitate learning and review.
The repository is organized by programming language and then by problem categories:
LeetCode-Solutions/
├── Attached Images/
│ ├── Qno_Fno_no.jpg
│ |
│ .
│ .
│ .
│ .
│ |
| └── Qno_Fno_no.jpg
|
├── LeetCode-Streak/
│ ├── Daily Questions 1
│ |
│ .
│ .
│ .
│ .
│ |
| └── Daily Questions nᵗʰ
|
├── Solutions/
│ ├── Two-Sum.md/
│ ├── Add-Two-Numbers.md/
│ .
│ .
│ .
│ |
│ └── nᵗʰ Question
|
├── CONTRIBUTING.md
├── LICENSE
├── LangParity C++ & Java.md
├── LeetCode-Solutions-Index.md
└── README.md
- LeetCode-Streak Folder: Contains LeetCode's Daily Challenge Problem's Solution -- Maintaining Streak
- File Naming: Solutions are named by their LeetCode problem number and title for easy navigation
- Solutions Folder: Contains LeetCode's Problems solved using languages either
C++
orJava
or both- File Naming: Solutions are named by their LeetCode problem title for easy navigation.
- Documentation Files:
- README.md: Provides an overview and usage instructions.
- CONTRIBUTING.md: Outlines guidelines for contributing to the repository.
- LeetCode-Solutions-Index.md: Outlines guidelines for accessing question's solution easily -- Indexing
- C++: Utilizes modern C++ standards (e.g., C++11/14/17) and STL for robust and optimized solutions.
- Java: Emphasizes clarity and efficiency using core Java libraries.
To compile a C++ solution (for example, the Two Sum problem):
Compilation
g++ -std=c++17 -o solution 001_Two_Sum.cpp
then
Execution
./solution
or
Compilation
g++ 001_Two_Sum.cpp
then
Execution
./a.exe
To compile and run a Java solution (for example, the Two Sum problem):
Compilation
javac 001_Two_Sum.java
then
Execution
java 001_Two_Sum
Feel free to adapt the commands based on your system configuration and project structure.
Contributions are welcome! If you’d like to add a new solution, improve an existing one, or fix any issues, please follow these steps:
- Fork the Repository: Create your own fork of the project.
- Create a Branch: Use a descriptive name for your branch (e.g.,
feature/add-two-sum-solution
). - Commit Changes: Follow the coding style used in the repository. Include comments explaining your approach and complexity.
- Submit a Pull Request: Provide a clear description of your changes and reference any related LeetCode problems.
Please review our CONTRIBUTING.md for detailed guidelines on code style, commit messages, and testing.
Each solution in this repository includes:
- Problem Description: A concise summary of the LeetCode problem.
- Approach Explanation: Detailed comments that explain the logic, algorithm, and complexity (both time and space).
- Clean Code: Emphasis on readability, modular design, and best practices.
- Test Cases: Example inputs and expected outputs are provided when applicable to verify the solution.
This project is licensed under the MIT License. You are free to use, modify, and distribute the code as long as proper attribution is provided.
Happy coding and best of luck on your journey to mastering algorithms and data structures!