mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-20 08:12:02 +00: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 == '(':
|
if parenthesis == '(':
|
||||||
stack.push(parenthesis)
|
stack.push(parenthesis)
|
||||||
elif parenthesis == ')':
|
elif parenthesis == ')':
|
||||||
|
if stack.is_empty():
|
||||||
|
return False
|
||||||
stack.pop()
|
stack.pop()
|
||||||
return not stack.is_empty()
|
return stack.is_empty()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user