diff --git a/data_structures/stacks/balanced_parentheses.py b/data_structures/stacks/balanced_parentheses.py index 96a4a0432..3229d19c8 100644 --- a/data_structures/stacks/balanced_parentheses.py +++ b/data_structures/stacks/balanced_parentheses.py @@ -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__':