Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added LeetCode problem 1,2 #2450

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

nageshnnazare
Copy link

@nageshnnazare nageshnnazare commented Apr 14, 2023

Created new directory for leetcode solutions, updated DIRECTORY.md and README.md

Description of Change

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

Created new directory for leetcode solutions
@nageshnnazare nageshnnazare marked this pull request as draft April 14, 2023 14:02
@nageshnnazare nageshnnazare marked this pull request as ready for review April 14, 2023 14:02
@Panquesito7 Panquesito7 added the enhancement New feature or request label Apr 14, 2023
leetcode/src/1.cpp Outdated Show resolved Hide resolved
leetcode/src/2.cpp Outdated Show resolved Hide resolved
leetcode/DIRECTORY.md Outdated Show resolved Hide resolved
@nageshnnazare nageshnnazare marked this pull request as draft April 14, 2023 19:12
@nageshnnazare nageshnnazare marked this pull request as ready for review April 14, 2023 19:19
- name: Write LeetCode DIRECTORY.md
run: |
python3 scripts/leetcode_directory_md.py 2>&1 | tee leetcode/DIRECTORY.md
git pull || true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this is not needed if we use fetch-depth in actions/checkout.
CC: @tjgurwara99.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is not needed.

scripts/leetcode_directory_md.py Outdated Show resolved Hide resolved

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be needed to be added in the files to prevent CI failures, unless we ignore the files in the CI, which is not 100% recommended, though.
What do you suggest we do here? I suggest using libraries/headers in the files to prevent CI failures.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking whether this directory could be excluded from the CI, as in the case of the C repo leetcode directory. Else we also need to add a driver code for each problem along with some test cases. What are your thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a main function or self-tests for the CI to pass, we just need to make the function work as expected with its necessary libraries/headers.
AFAIK, the C repository doesn't ignore the leetcode directory in the CI.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Panquesito7
Updated the cpp files and the README file for these changes.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally against merging PR's through a workflow but I leave this decision to your @Panquesito7

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to remove that part of the code so that we can check the PR to see if it is 100% fine.
Reviewing wouldn't take long as I'm always aware of incoming PRs in this repository. 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the yml file @Panquesito7 @tjgurwara99

@nageshnnazare nageshnnazare marked this pull request as draft April 15, 2023 06:06
@nageshnnazare nageshnnazare marked this pull request as ready for review April 15, 2023 06:15
# when doing a git push
name: leetcode_directory_writer
on:
push:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this for every push? 🤔 I think it suffices to have this for a pull_request instead... What do you think @Panquesito7?

@nageshnnazare
Copy link
Author

nageshnnazare commented Apr 16, 2023

Hi @Panquesito7, @tjgurwara99
For problem 2, the CI is failing with the following warnings:

/home/runner/work/C-Plus-Plus/C-Plus-Plus/leetcode/src/2.cpp:29:9: warning: assigning newly created 'gsl::owner<>' to non-owner 'ListNode *' [cppcoreguidelines-owning-memory]
sum->next = new ListNode(val%10);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/C-Plus-Plus/C-Plus-Plus/leetcode/src/2.cpp:35:9: warning: assigning newly created 'gsl::owner<>' to non-owner 'ListNode *' [cppcoreguidelines-owning-memory]
sum->next = new ListNode(carry);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I guess it is because of the use of raw pointers instead of smart pointers. Is there a way to suppress this?

(This may require changing the definition of the ListNode struct, which is already defined by the platform)

struct ListNode {
int val;
std::unique_ptr next; // Use unique_ptr here
...
};

@realstealthninja
Copy link
Collaborator

Does this directory also fall under doxygen style guidelines?

@Panquesito7
Copy link
Member

Does this directory also fall under doxygen style guidelines?

I believe so. Not required, but if added, it's better, IMO.

@Panquesito7
Copy link
Member

Panquesito7 commented Apr 26, 2023

Is there a way to suppress this?

It'd be better to use smart pointers, though.
I found this to convert raw to a smart pointer, it may help: https://www.sololearn.com/Discuss/1958592/how-can-i-replace-raw-pointers-with-smart-pointers

@realstealthninja
Copy link
Collaborator

Does this directory also fall under doxygen style guidelines?

I believe so. Not required, but if added, it's better, IMO.

Ah alright!

@github-actions
Copy link
Contributor

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label May 27, 2023
@Panquesito7 Panquesito7 removed the stale Author has not responded to the comments for over 2 weeks label May 30, 2023
@github-actions
Copy link
Contributor

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label Jun 30, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2023

Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!

@github-actions github-actions bot closed this Jul 7, 2023
@Panquesito7 Panquesito7 reopened this Jul 7, 2023
@Panquesito7 Panquesito7 added dont-close This issue/pull request shouldn't be closed and removed stale Author has not responded to the comments for over 2 weeks labels Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dont-close This issue/pull request shouldn't be closed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants