We're glad you're interested in adding C++ LeetCode solutions to the repository.
Here we'll be explaining how to contribute to LeetCode solutions properly.
First off, you'll need to fork the repository here.
Then, you'll need to clone the repository to your local machine.
git clone https://github.com/your-username/C-Plus-Plus.gitAfter that, you'll need to create a new branch for your solution.
git checkout -b solution/your-solution-nameAll LeetCode problems can be found here.
If you have a solution to any of these problems (which are not being repeated, that's great! Here are the steps:
- Add a new file in
leetcode/srcwith the number of the problem.- For example: if the problem's number is 98, the filename should be
98.cpp.
- For example: if the problem's number is 98, the filename should be
- Provide a small description of the solution at the top of the file. A function should go below that. For example:
/**
* Return an vector of vector of size returnSize.
* The sizes of the vectors are returned as returnColumnSizes vector.
* Note: Both returned vector and columnSizes vector must be dynamically allocated, assume caller calls free.
*/- Do not provide a
mainfunction. Use the required standalone functions instead. - Doxygen documentation isn't used in LeetCode solutions. Simple/small documentation or comments should be fine.
- Please include dependency libraries/headers such as
<iostream>,<vector>along with theSolutionclass to the problem. This will help the CI to succeed without the dependency errors.
Note There was a requirement to update the
leetcode/DIRECTORY.mdfile with details of the solved problem. It's not required anymore. The information about the problem is fetched automatically throughout the LeetCode API.
Once you're done with adding a new LeetCode solution, it's time we make a pull request.
- First, stage your changes.
git add leetcode/src/98.cpp # Use `git add .` to stage all changes.- Then, commit your changes.
git commit -m "feat: add LeetCode problem 98" -m "Commit description" # Optional- Finally, push your changes to your forked repository.
git push origin solution/your-solution-name:solution/your-solution-name- You're done now! You just have to make a pull request. 🎉
If you need any help, don't hesitate to ask and join our Discord server! 🙂