+ 1
Balanced Parentheses solution question
I'm solving the final challenge in Python Data Structures. They ask for stack solution. But I can't seem to figure out why this solution wouldn't work. Why doesn't the following code solve the balanced parentheses? def balanced(expression): #your code goes here a = expression.count("(") b = expression.count(")") if "(" in expression and ")" in expression: if a == b and expression.find("(") < expression.find(")"): return True else: return False else: return "False" print(balanced(input()))
3 odpowiedzi
+ 4
Try this:
(()))(
+ 2
Oh, I see... It is a problem... Thank you, Brian!
+ 1
You're welcome!