-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Balanced parentheses #3768
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
Balanced parentheses #3768
Conversation
return stack.is_empty() | ||
|
||
|
||
def is_paired(left_bracket: str, right_bracket: str) -> bool: | ||
""" | ||
>>> brackets = {"(" : ")", "[" : "]", "{" : "}"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s make this dict a global named bracket_pairs
and then we can eliminate is_paired()
because it is the same as bracket_pairs[left_bracket] == right_bracket
@cclauss @poyea @dhruvmanila Can you review this PR 👍 |
Co-authored-by: Christian Clauss <[email protected]>
>>> balanced_parentheses("[()]{}{[()()]()}") | ||
True | ||
>>> balanced_parentheses("[(])") | ||
False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a string that has no brackets and also an empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Please review again.
Co-authored-by: Christian Clauss <[email protected]>
* Fixed balanced_parentheses.py * fixed pre-commit * eliminate is_paired * remove unused line * updating DIRECTORY.md * Update data_structures/stacks/balanced_parentheses.py Co-authored-by: Christian Clauss <[email protected]> * Add more test cases * Update data_structures/stacks/balanced_parentheses.py Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
* Fixed balanced_parentheses.py * fixed pre-commit * eliminate is_paired * remove unused line * updating DIRECTORY.md * Update data_structures/stacks/balanced_parentheses.py Co-authored-by: Christian Clauss <[email protected]> * Add more test cases * Update data_structures/stacks/balanced_parentheses.py Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
* Fixed balanced_parentheses.py * fixed pre-commit * eliminate is_paired * remove unused line * updating DIRECTORY.md * Update data_structures/stacks/balanced_parentheses.py Co-authored-by: Christian Clauss <[email protected]> * Add more test cases * Update data_structures/stacks/balanced_parentheses.py Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
* Fixed balanced_parentheses.py * fixed pre-commit * eliminate is_paired * remove unused line * updating DIRECTORY.md * Update data_structures/stacks/balanced_parentheses.py Co-authored-by: Christian Clauss <[email protected]> * Add more test cases * Update data_structures/stacks/balanced_parentheses.py Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.