mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Fixed bug where an empty stack would cause error
This commit is contained in:
parent
a8cfc14737
commit
2e2fadf4db
@ -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__':
|
||||
|
Loading…
Reference in New Issue
Block a user