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

Solved challenge valid parenthesis #67

Merged
merged 1 commit into from
Oct 7, 2018
Merged

Solved challenge valid parenthesis #67

merged 1 commit into from
Oct 7, 2018

Conversation

Tijs-B
Copy link
Contributor

@Tijs-B Tijs-B commented Oct 6, 2018

I approached the problem using a stack, where on the top of the stack the last parenthesis is stored ("(", "{" or "["). On each character, an opening parenthesis is pushed onto the stack, and for a closed parenthesis the last item on the stack is popped and checked if it is equal to the current parenthesis. At the end of the string, the stack is checked if it is empty, because otherwise there would be an opening parenthesis without a closing one.

How to use the solution:
Just use the functoin has_valid_parens(string) which returns True or False whether the given string has valid parenthesis.

@Tijs-B Tijs-B mentioned this pull request Oct 6, 2018
@the-vampiire the-vampiire merged commit c2e08fe into the-vampiire:master Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants