This repository contains worked solutions to LeetCode problems implemented in C++. Each problem is placed in a dedicated folder named with the problem number and a short title.
Goals:
- Provide clear, idiomatic C++ solutions.
- Show typical approaches and complexity analysis.
- Serve as a reference and study aid for algorithm practice.
- Top-level folders are organized by problem number and short name, for example:
0001-two-sum/— contains one or more solutions and a problem README.
- Typical files inside a problem folder:
solution.cpp— primary solution implementation.- Additional variants:
brute_force.cpp,two_pointer.cpp,hashing.cpp,kadane.cpp, etc. README.md— problem-specific notes, approach, and complexity.
- Filenames: prefer descriptive names like
solution.cpportwo_pointer.cppwhen multiple approaches exist. - Code: modern C++ (at least C++17) with readable variable names and minimal dependencies.
- Each problem folder should include a short
README.mddescribing the approach and time/space complexity.
You can compile an individual solution with g++ (C++17). Example:
g++ -std=c++17 -O2 path/to/problem/solution.cpp -o solution && ./solutionIf a solution reads input from stdin, provide input via redirection or a here-doc. Example:
./solution < input.txtFor Windows PowerShell (g++ in PATH):
g++ -std=c++17 -O2 .\0001-two-sum\solution.cpp -o solution.exe; .\solution.exe- Create a new folder named with a zero-padded problem number and short title, e.g.
0123-my-problem/. - Add your solution file(s), preferably
solution.cppas the canonical solution. - Add a
README.mdinside the folder summarizing the approach, complexities, and any edge cases. - (Optional) Add multiple variants when relevant, labeling them clearly (e.g.,
brute_force.cpp,dp.cpp).
- Prefer clarity over clever micro-optimizations.
- Comment non-obvious logic and explain tricky invariants in the problem README.
- Keep functions small and focused; implement helpers when appropriate.
- Use
std::vector,std::string,std::unordered_map, and STL algorithms where applicable.
Contributions are welcome. To contribute:
- Fork the repo and create a branch for your changes.
- Add or update a problem folder with solution(s) and
README.md. - Open a pull request with a clear description of the approach.
This repository does not include an explicit license. If you want to reuse or redistribute code, please contact the repo owner or add a license file.