From c4e557fab7c4e679576ee104f50eacc4fb50898a Mon Sep 17 00:00:00 2001 From: Nagesh N Nazare <85761012+nageshnnazare@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:43:20 +0000 Subject: [PATCH 01/11] feat: add LeetCode problem 1,2 Created new directory for leetcode solutions --- leetcode/DIRECTORY.md | 9 ++++++ leetcode/README.md | 69 +++++++++++++++++++++++++++++++++++++++++++ leetcode/src/1.cpp | 24 +++++++++++++++ leetcode/src/2.cpp | 37 +++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 leetcode/DIRECTORY.md create mode 100644 leetcode/README.md create mode 100644 leetcode/src/1.cpp create mode 100644 leetcode/src/2.cpp diff --git a/leetcode/DIRECTORY.md b/leetcode/DIRECTORY.md new file mode 100644 index 00000000000..4d6efaafa8b --- /dev/null +++ b/leetcode/DIRECTORY.md @@ -0,0 +1,9 @@ + +# LeetCode + +### LeetCode Algorithm + +| # | Title| Solution | Difficulty | +| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------- | ---------- | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum)| [C++](./src/1.cpp) | Easy | +| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers)| [C++](./src/2.cpp) | Medium | diff --git a/leetcode/README.md b/leetcode/README.md new file mode 100644 index 00000000000..ef14392c250 --- /dev/null +++ b/leetcode/README.md @@ -0,0 +1,69 @@ +# 📚 Contributing 📚 + +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. + +## 💻 Cloning/setting up the project 💻 + +First off, you'll need to fork the repository [**here**](https://github.com/TheAlgorithms/C-Plus-Plus/fork).\ +Then, you'll need to clone the repository to your local machine. + +```bash +git clone https://github.com/your-username/C-Plus-Plus.git +``` + +After that, you'll need to create a new branch for your solution. + +```bash +git checkout -b solution/your-solution-name +``` + +## 📝 Adding a new solution 📝 + +All LeetCode problems can be found [**here**](https://leetcode.com/problemset/all/).\ +If you have a solution to any of these problems (which are not being **repeated**, that's great! Here are the steps: + +1. Add a new file in `leetcode/src` with the number of the problem. + - For example: if the problem's number is 98, the filename should be `98.cpp`. +2. Provide a small description of the solution at the top of the file. A function should go below that. For example: + +```c +/** + * 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. + */ +``` + +3. Do not provide a `main` function. Use the required standalone functions instead. +4. Doxygen documentation isn't used in LeetCode solutions. Simple/small documentation or comments should be fine. +5. Don't include libraries/headers such as `iostream`. Your file should be the solution to the problem only. + +> **Note** +> 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. + +## 📦 Committing your changes 📦 + +Once you're done with adding a new LeetCode solution, it's time we make a pull request. + +1. First, stage your changes. + +```bash +git add leetcode/src/98.cpp # Use `git add .` to stage all changes. +``` + +2. Then, commit your changes. + +```bash +git commit -m "feat: add LeetCode problem 98" -m "Commit description" # Optional +``` + +3. Finally, push your changes to your forked repository. + +```bash +git push origin solution/your-solution-name:solution/your-solution-name +``` + +4. You're done now! You just have to make a [**pull request**](https://github.com/TheAlgorithms/C-Plus-Plus/compare). 🎉 + +If you need any help, don't hesitate to ask and join our [**Discord server**](https://the-algorithms.com/discord)! 🙂 \ No newline at end of file diff --git a/leetcode/src/1.cpp b/leetcode/src/1.cpp new file mode 100644 index 00000000000..dee599d7c6d --- /dev/null +++ b/leetcode/src/1.cpp @@ -0,0 +1,24 @@ +/* +* Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. +* You may assume that each input would have exactly one solution, and you may not use the same element twice. +*/ + +class Solution { +public: + std::vector twoSum(std::vector& nums, int target) { + std::unordered_map mp; // value:index + std::vector res; + + for (int i = 0; i < nums.size(); i++) { + int diff = target - nums[i]; + + if (mp.find(diff) != mp.end()) { + res.push_back(mp[diff]); + res.push_back(i); + return res; + } + mp[nums[i]] = i; + } + return res; + } +}; \ No newline at end of file diff --git a/leetcode/src/2.cpp b/leetcode/src/2.cpp new file mode 100644 index 00000000000..6a47c1abaff --- /dev/null +++ b/leetcode/src/2.cpp @@ -0,0 +1,37 @@ +/* You are given two non - empty linked lists representing two non - negative integers. +* The digits are stored in reverse order, and each of their nodes contains a single digit. +* Add the two numbersand return the sum as a linked list. +*/ + +/* + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution { +public: + ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { + int carry = 0; + ListNode head; + ListNode* sum = &head; + + while (l1 || l2) { + int val = carry + (l1 ? l1->val : 0) + (l2 ? l2->val : 0); + carry = val / 10; + sum->next = new ListNode(val % 10); + sum = sum->next; + l1 = (l1 ? l1->next : nullptr); + l2 = (l2 ? l2->next : nullptr); + } + if (carry) { + sum->next = new ListNode(carry); + } + + return head.next; + } +}; \ No newline at end of file From 505eb91a5e65515f04b9d2be53a47493cd3e4a67 Mon Sep 17 00:00:00 2001 From: David Leal Date: Fri, 14 Apr 2023 12:11:15 -0600 Subject: [PATCH 02/11] chore: apply suggestions from code review --- leetcode/src/1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leetcode/src/1.cpp b/leetcode/src/1.cpp index dee599d7c6d..649f23841bd 100644 --- a/leetcode/src/1.cpp +++ b/leetcode/src/1.cpp @@ -21,4 +21,4 @@ class Solution { } return res; } -}; \ No newline at end of file +}; From 7435ff1238575648961fd22d3823187f437b3931 Mon Sep 17 00:00:00 2001 From: David Leal Date: Fri, 14 Apr 2023 12:11:25 -0600 Subject: [PATCH 03/11] chore: apply suggestions from code review --- leetcode/src/2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leetcode/src/2.cpp b/leetcode/src/2.cpp index 6a47c1abaff..11eecbd70e0 100644 --- a/leetcode/src/2.cpp +++ b/leetcode/src/2.cpp @@ -34,4 +34,4 @@ class Solution { return head.next; } -}; \ No newline at end of file +}; From ce1698f64c796280592c311849bbd55f7ce0b2b8 Mon Sep 17 00:00:00 2001 From: Nagesh N Nazare <85761012+nageshnnazare@users.noreply.github.com> Date: Fri, 14 Apr 2023 18:48:02 +0000 Subject: [PATCH 04/11] feat: added github workflow action file for leetcode Directory.md file --- .../workflows/leetcode_directory_writer.yml | 39 +++++++++++++++++++ leetcode/DIRECTORY.md | 9 ----- 2 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/leetcode_directory_writer.yml delete mode 100644 leetcode/DIRECTORY.md diff --git a/.github/workflows/leetcode_directory_writer.yml b/.github/workflows/leetcode_directory_writer.yml new file mode 100644 index 00000000000..caa93e82523 --- /dev/null +++ b/.github/workflows/leetcode_directory_writer.yml @@ -0,0 +1,39 @@ +# The objective of this GitHub Action is to update the leetcode DIRECTORY.md file (if needed) +# when doing a git push +name: leetcode_directory_writer +on: + push: + paths: + - 'leetcode/src/**.cpp' +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - name: Add python dependencies + run: | + pip install requests + - name: Write LeetCode DIRECTORY.md + run: | + python3 scripts/leetcode_directory_md.py 2>&1 | tee leetcode/DIRECTORY.md + git pull || true + - name: Commit and push changes + uses: stefanzweifel/git-auto-commit-action@v4 + id: commit-push + with: + commit_message: 'docs: updating `leetcode/DIRECTORY.md`' + branch: 'leetcode-directory-${{ github.sha }}' + create_branch: true + - name: Creating and merging the PR + shell: bash + if: steps.commit-push.outputs.changes_detected == 'true' + run: | + gh pr create --base ${GITHUB_REF##*/} --head leetcode-directory-${{ github.sha }} --title 'docs: updating `leetcode/DIRECTORY.md`' --body 'Updated LeetCode directory (see the diff. for changes).' + gh pr merge --admin --merge --subject 'docs: updating `leetcode/DIRECTORY.md' --delete-branch + env: + GH_TOKEN: ${{ github.token }} diff --git a/leetcode/DIRECTORY.md b/leetcode/DIRECTORY.md deleted file mode 100644 index 4d6efaafa8b..00000000000 --- a/leetcode/DIRECTORY.md +++ /dev/null @@ -1,9 +0,0 @@ - -# LeetCode - -### LeetCode Algorithm - -| # | Title| Solution | Difficulty | -| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------- | ---------- | -| 1 | [Two Sum](https://leetcode.com/problems/two-sum)| [C++](./src/1.cpp) | Easy | -| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers)| [C++](./src/2.cpp) | Medium | From 2a6c4182e8643ea047ae2175152b29bc46e4b28c Mon Sep 17 00:00:00 2001 From: Nagesh N Nazare <85761012+nageshnnazare@users.noreply.github.com> Date: Fri, 14 Apr 2023 19:17:17 +0000 Subject: [PATCH 05/11] added leetcode-python script for directory file generation --- scripts/leetcode_directory_md.py | 124 +++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 scripts/leetcode_directory_md.py diff --git a/scripts/leetcode_directory_md.py b/scripts/leetcode_directory_md.py new file mode 100644 index 00000000000..62a2fc6b21f --- /dev/null +++ b/scripts/leetcode_directory_md.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 + +from dataclasses import dataclass +from os import listdir +from pathlib import Path + +import requests + + +@dataclass +class Task: + """The task dataclass. Container for task info""" + + id: str + title: str + solution: str + difficulty: str + + +def fetch_leetcode_folder_tasks(solutions_folder: Path) -> list[Task]: + """Fetch leetcode tasks from the Leetcode""" + + # Fetch tasks info from the leetcode API. + resp = requests.get("https://leetcode.com/api/problems/algorithms/", timeout=10) + content_dict = resp.json() + + raw_tasks_id_dict = {} + + for task in content_dict["stat_status_pairs"]: + task_stat = task["stat"] + raw_tasks_id_dict[str(task_stat["frontend_question_id"])] = task + + # Generate result tasks info to be inserted into the document + tasks_list = [] + + difficulty = {1: "Easy", 2: "Medium", 3: "Hard"} + + for fl in listdir(solutions_folder): + task_id = fl.split(".")[0] + + raw_task = raw_tasks_id_dict.get(task_id, None) + if raw_task is None: + continue + + raw_task_stat = raw_task["stat"] + tasks_list.append( + Task( + id=f'{raw_task_stat["frontend_question_id"]}', + title=f'[{raw_task_stat["question__title"]}](https://leetcode.com/problems/{raw_task_stat["question__title_slug"]})', + solution=f"[C++](./src/{fl})", + difficulty=f'{difficulty.get(raw_task["difficulty"]["level"], "")}', + ) + ) + + return tasks_list + + +HEADER_ID = "#" +HEADER_TITLE = "Title" +HEADER_SOLUTION = "Solution" +HEADER_DIFFICULTY = "Difficulty" +SEPARATOR = "-" + + +def print_directory_md(tasks_list: list[Task]) -> None: + """Print tasks into the stdout""" + + def get_max_len(get_item): + return max(list(map(lambda x: len(get_item(x)), tasks_list))) + + id_max_length = max(get_max_len(lambda x: x.id), len(HEADER_ID)) + title_max_length = max(get_max_len(lambda x: x.title), len(HEADER_TITLE)) + solution_max_length = max(get_max_len(lambda x: x.solution), len(HEADER_SOLUTION)) + difficulty_max_length = max( + get_max_len(lambda x: x.difficulty), len(HEADER_DIFFICULTY) + ) + + def formatted_string(header, title, solution, difficulty): + return ( + f"| {header.rjust(id_max_length)} " + + f"| {title.ljust(title_max_length)} " + + f"| {solution.ljust(solution_max_length)} " + + f"| {difficulty.ljust(difficulty_max_length)} |" + ) + + tasks_rows = [] + + tasks_rows.append( + formatted_string(HEADER_ID, HEADER_TITLE, HEADER_SOLUTION, HEADER_DIFFICULTY) + ) + tasks_rows.append( + formatted_string( + id_max_length * SEPARATOR, + title_max_length * SEPARATOR, + solution_max_length * SEPARATOR, + difficulty_max_length * SEPARATOR, + ) + ) + + tasks_list.sort(key=lambda x: int(x.id.strip())) + + for task in tasks_list: + tasks_rows.append( + formatted_string(task.id, task.title, task.solution, task.difficulty) + ) + + print( + """ +# LeetCode + +### LeetCode Algorithm +""" + ) + + for item in tasks_rows: + print(item) + + +if __name__ == "__main__": + top_dir = Path(".") + solutions_folder = top_dir / "leetcode" / "src" + + tasks_list = fetch_leetcode_folder_tasks(solutions_folder) + print_directory_md(tasks_list) \ No newline at end of file From 9b65a200402d899a8a98432de6b4a20562410076 Mon Sep 17 00:00:00 2001 From: Nagesh N Nazare <85761012+nageshnnazare@users.noreply.github.com> Date: Sat, 15 Apr 2023 00:57:13 +0530 Subject: [PATCH 06/11] Update scripts/leetcode_directory_md.py Co-authored-by: David Leal --- scripts/leetcode_directory_md.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/leetcode_directory_md.py b/scripts/leetcode_directory_md.py index 62a2fc6b21f..4fa40728778 100644 --- a/scripts/leetcode_directory_md.py +++ b/scripts/leetcode_directory_md.py @@ -121,4 +121,4 @@ def formatted_string(header, title, solution, difficulty): solutions_folder = top_dir / "leetcode" / "src" tasks_list = fetch_leetcode_folder_tasks(solutions_folder) - print_directory_md(tasks_list) \ No newline at end of file + print_directory_md(tasks_list) From 82e3e47f1b7ee43ce7d1307499726e1067ca750d Mon Sep 17 00:00:00 2001 From: Nagesh N Nazare <85761012+nageshnnazare@users.noreply.github.com> Date: Sat, 15 Apr 2023 05:45:43 +0000 Subject: [PATCH 07/11] feat: added header files to solutions to help CI * Updated the leetcode Readme.md file --- leetcode/README.md | 6 +++--- leetcode/src/1.cpp | 9 ++++++--- leetcode/src/2.cpp | 21 +++++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/leetcode/README.md b/leetcode/README.md index ef14392c250..5d651b16a4e 100644 --- a/leetcode/README.md +++ b/leetcode/README.md @@ -24,7 +24,7 @@ All LeetCode problems can be found [**here**](https://leetcode.com/problemset/al If you have a solution to any of these problems (which are not being **repeated**, that's great! Here are the steps: 1. Add a new file in `leetcode/src` with 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 `98.cpp`. 2. Provide a small description of the solution at the top of the file. A function should go below that. For example: ```c @@ -37,7 +37,7 @@ If you have a solution to any of these problems (which are not being **repeated* 3. Do not provide a `main` function. Use the required standalone functions instead. 4. Doxygen documentation isn't used in LeetCode solutions. Simple/small documentation or comments should be fine. -5. Don't include libraries/headers such as `iostream`. Your file should be the solution to the problem only. +5. Please include dependency libraries/headers such as ``, `` along with the `Solution` class to the problem. This will help the CI to succeed without the dependency errors. > **Note** > 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. @@ -66,4 +66,4 @@ git push origin solution/your-solution-name:solution/your-solution-name 4. You're done now! You just have to make a [**pull request**](https://github.com/TheAlgorithms/C-Plus-Plus/compare). 🎉 -If you need any help, don't hesitate to ask and join our [**Discord server**](https://the-algorithms.com/discord)! 🙂 \ No newline at end of file +If you need any help, don't hesitate to ask and join our [**Discord server**](https://the-algorithms.com/discord)! 🙂 diff --git a/leetcode/src/1.cpp b/leetcode/src/1.cpp index 649f23841bd..683757c1dc9 100644 --- a/leetcode/src/1.cpp +++ b/leetcode/src/1.cpp @@ -1,8 +1,11 @@ /* -* Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. -* You may assume that each input would have exactly one solution, and you may not use the same element twice. -*/ + * Given an array of integers nums and an integer target, return indices of the + * two numbers such that they add up to target. + * You may assume that each input would have exactly one solution, and you may not use the same element twice. + */ +#include +#include class Solution { public: std::vector twoSum(std::vector& nums, int target) { diff --git a/leetcode/src/2.cpp b/leetcode/src/2.cpp index 11eecbd70e0..ea7e992dc9c 100644 --- a/leetcode/src/2.cpp +++ b/leetcode/src/2.cpp @@ -1,18 +1,19 @@ /* You are given two non - empty linked lists representing two non - negative integers. -* The digits are stored in reverse order, and each of their nodes contains a single digit. -* Add the two numbersand return the sum as a linked list. -*/ + * The digits are stored in reverse order, and each of their nodes contains a single digit. + * Add the two numbersand return the sum as a linked list. + */ /* * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode() : val(0), next(nullptr) {} - * ListNode(int x) : val(x), next(nullptr) {} - * ListNode(int x, ListNode *next) : val(x), next(next) {} - * }; */ +struct ListNode { + int val; + ListNode *next; + ListNode() : val(0), next(nullptr) {} + ListNode(int x) : val(x), next(nullptr) {} + ListNode(int x, ListNode *next) : val(x), next(next) {} +}; + class Solution { public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { From 079a161ba936951c4505b25c39f6686bf278a191 Mon Sep 17 00:00:00 2001 From: Nagesh N Nazare <85761012+nageshnnazare@users.noreply.github.com> Date: Sat, 15 Apr 2023 06:13:34 +0000 Subject: [PATCH 08/11] feat: update the yml file for leetcode dir actions --- .github/workflows/leetcode_directory_writer.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/leetcode_directory_writer.yml b/.github/workflows/leetcode_directory_writer.yml index caa93e82523..eeaf1f39ba8 100644 --- a/.github/workflows/leetcode_directory_writer.yml +++ b/.github/workflows/leetcode_directory_writer.yml @@ -18,10 +18,6 @@ jobs: - name: Add python dependencies run: | pip install requests - - name: Write LeetCode DIRECTORY.md - run: | - python3 scripts/leetcode_directory_md.py 2>&1 | tee leetcode/DIRECTORY.md - git pull || true - name: Commit and push changes uses: stefanzweifel/git-auto-commit-action@v4 id: commit-push @@ -29,11 +25,3 @@ jobs: commit_message: 'docs: updating `leetcode/DIRECTORY.md`' branch: 'leetcode-directory-${{ github.sha }}' create_branch: true - - name: Creating and merging the PR - shell: bash - if: steps.commit-push.outputs.changes_detected == 'true' - run: | - gh pr create --base ${GITHUB_REF##*/} --head leetcode-directory-${{ github.sha }} --title 'docs: updating `leetcode/DIRECTORY.md`' --body 'Updated LeetCode directory (see the diff. for changes).' - gh pr merge --admin --merge --subject 'docs: updating `leetcode/DIRECTORY.md' --delete-branch - env: - GH_TOKEN: ${{ github.token }} From 24379ec783765c02430a6ad1c1de03179d03919d Mon Sep 17 00:00:00 2001 From: Nagesh N Nazare <85761012+nageshnnazare@users.noreply.github.com> Date: Sat, 15 Apr 2023 10:26:08 +0000 Subject: [PATCH 09/11] feat: fix for CI warnings in 2.cpp --- leetcode/src/2.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/leetcode/src/2.cpp b/leetcode/src/2.cpp index ea7e992dc9c..85e0757449a 100644 --- a/leetcode/src/2.cpp +++ b/leetcode/src/2.cpp @@ -3,36 +3,38 @@ * Add the two numbersand return the sum as a linked list. */ -/* +#include + + /* * Definition for singly-linked list. */ struct ListNode { int val; ListNode *next; - ListNode() : val(0), next(nullptr) {} + explicit ListNode() : val(0), next(nullptr) {} ListNode(int x) : val(x), next(nullptr) {} ListNode(int x, ListNode *next) : val(x), next(next) {} }; class Solution { public: - ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { - int carry = 0; - ListNode head; - ListNode* sum = &head; - - while (l1 || l2) { - int val = carry + (l1 ? l1->val : 0) + (l2 ? l2->val : 0); - carry = val / 10; - sum->next = new ListNode(val % 10); - sum = sum->next; - l1 = (l1 ? l1->next : nullptr); - l2 = (l2 ? l2->next : nullptr); - } - if (carry) { - sum->next = new ListNode(carry); - } +ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { + int carry = 0; + std::unique_ptr head(new ListNode(0)); + ListNode* sum = head.get(); - return head.next; + while(l1 || l2) { + int val = carry + (l1 ? l1->val : 0) + (l2 ? l2->val : 0); + carry = val/10; + sum->next = new ListNode(val%10); + sum = sum->next; + l1 = (l1 ? l1->next : nullptr); + l2 = (l2 ? l2->next : nullptr); } + if(carry){ + sum->next = new ListNode(carry); + } + + return head->next; +} }; From c54849d2fbbade3d08bd8f2bcf8ef145bd59596a Mon Sep 17 00:00:00 2001 From: Nagesh N Nazare <85761012+nageshnnazare@users.noreply.github.com> Date: Sun, 16 Apr 2023 13:25:31 +0000 Subject: [PATCH 10/11] feat: updated the yml and cpp files --- .github/workflows/leetcode_directory_writer.yml | 3 +++ leetcode/src/2.cpp | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/leetcode_directory_writer.yml b/.github/workflows/leetcode_directory_writer.yml index eeaf1f39ba8..9f3ac5b3ffe 100644 --- a/.github/workflows/leetcode_directory_writer.yml +++ b/.github/workflows/leetcode_directory_writer.yml @@ -18,6 +18,9 @@ jobs: - name: Add python dependencies run: | pip install requests + - name: Write LeetCode DIRECTORY.md + run: | + python3 scripts/leetcode_directory_md.py 2>&1 | tee leetcode/DIRECTORY.md - name: Commit and push changes uses: stefanzweifel/git-auto-commit-action@v4 id: commit-push diff --git a/leetcode/src/2.cpp b/leetcode/src/2.cpp index 85e0757449a..bc9573f9430 100644 --- a/leetcode/src/2.cpp +++ b/leetcode/src/2.cpp @@ -12,8 +12,8 @@ struct ListNode { int val; ListNode *next; explicit ListNode() : val(0), next(nullptr) {} - ListNode(int x) : val(x), next(nullptr) {} - ListNode(int x, ListNode *next) : val(x), next(next) {} + explicit ListNode(int x) : val(x), next(nullptr) {} + explicit ListNode(int x, ListNode *next) : val(x), next(next) {} }; class Solution { From 6c3424cd205b90a032128a605d175ba99dc123f7 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 19:53:40 +0530 Subject: [PATCH 11/11] fix: use on pull request instead of on push --- .github/workflows/leetcode_directory_writer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/leetcode_directory_writer.yml b/.github/workflows/leetcode_directory_writer.yml index 9f3ac5b3ffe..7a29e114804 100644 --- a/.github/workflows/leetcode_directory_writer.yml +++ b/.github/workflows/leetcode_directory_writer.yml @@ -2,7 +2,7 @@ # when doing a git push name: leetcode_directory_writer on: - push: + pull_request: paths: - 'leetcode/src/**.cpp' jobs: