|
| 1 | +# 📚 Contributing 📚 |
| 2 | + |
| 3 | +We're glad you're interested in adding C++ LeetCode solutions to the repository.\ |
| 4 | +Here we'll be explaining how to contribute to LeetCode solutions properly. |
| 5 | + |
| 6 | +## 💻 Cloning/setting up the project 💻 |
| 7 | + |
| 8 | +First off, you'll need to fork the repository [**here**](https://github.com/TheAlgorithms/C-Plus-Plus/fork).\ |
| 9 | +Then, you'll need to clone the repository to your local machine. |
| 10 | + |
| 11 | +```bash |
| 12 | +git clone https://github.com/your-username/C-Plus-Plus.git |
| 13 | +``` |
| 14 | + |
| 15 | +After that, you'll need to create a new branch for your solution. |
| 16 | + |
| 17 | +```bash |
| 18 | +git checkout -b solution/your-solution-name |
| 19 | +``` |
| 20 | + |
| 21 | +## 📝 Adding a new solution 📝 |
| 22 | + |
| 23 | +All LeetCode problems can be found [**here**](https://leetcode.com/problemset/all/).\ |
| 24 | +If you have a solution to any of these problems (which are not being **repeated**, that's great! Here are the steps: |
| 25 | + |
| 26 | +1. Add a new file in `leetcode/src` with the number of the problem. |
| 27 | + - For example: if the problem's number is 98, the filename should be `98.cpp`. |
| 28 | +2. Provide a small description of the solution at the top of the file. A function should go below that. For example: |
| 29 | + |
| 30 | +```c |
| 31 | +/** |
| 32 | + * Return an vector of vector of size returnSize. |
| 33 | + * The sizes of the vectors are returned as returnColumnSizes vector. |
| 34 | + * Note: Both returned vector and columnSizes vector must be dynamically allocated, assume caller calls free. |
| 35 | + */ |
| 36 | +``` |
| 37 | + |
| 38 | +3. Do not provide a `main` function. Use the required standalone functions instead. |
| 39 | +4. Doxygen documentation isn't used in LeetCode solutions. Simple/small documentation or comments should be fine. |
| 40 | +5. Don't include libraries/headers such as `iostream`. Your file should be the solution to the problem only. |
| 41 | + |
| 42 | +> **Note** |
| 43 | +> There was a requirement to update the `leetcode/DIRECTORY.md` file with details of the solved problem. It's not required anymore. The information about the problem is fetched automatically throughout the LeetCode API. |
| 44 | +
|
| 45 | +## 📦 Committing your changes 📦 |
| 46 | + |
| 47 | +Once you're done with adding a new LeetCode solution, it's time we make a pull request. |
| 48 | + |
| 49 | +1. First, stage your changes. |
| 50 | + |
| 51 | +```bash |
| 52 | +git add leetcode/src/98.cpp # Use `git add .` to stage all changes. |
| 53 | +``` |
| 54 | + |
| 55 | +2. Then, commit your changes. |
| 56 | + |
| 57 | +```bash |
| 58 | +git commit -m "feat: add LeetCode problem 98" -m "Commit description" # Optional |
| 59 | +``` |
| 60 | + |
| 61 | +3. Finally, push your changes to your forked repository. |
| 62 | + |
| 63 | +```bash |
| 64 | +git push origin solution/your-solution-name:solution/your-solution-name |
| 65 | +``` |
| 66 | + |
| 67 | +4. You're done now! You just have to make a [**pull request**](https://github.com/TheAlgorithms/C-Plus-Plus/compare). 🎉 |
| 68 | + |
| 69 | +If you need any help, don't hesitate to ask and join our [**Discord server**](https://the-algorithms.com/discord)! 🙂 |
0 commit comments