Fixed bug where an empty stack would cause error

This commit is contained in:
Mikael Souza 2018-12-17 10:45:54 -04:00
parent a8cfc14737
commit 2e2fadf4db

View File

@ -12,8 +12,10 @@ def balanced_parentheses(parentheses):
if parenthesis == '(':
stack.push(parenthesis)
elif parenthesis == ')':
if stack.is_empty():
return False
stack.pop()
return not stack.is_empty()
return stack.is_empty()
if __name__ == '__main__':