+ 2
Need help my code is failing to give the correct output for the last hidden case on Balanced Parentheses
Here is my code: def balanced(expression): #your code goes here openB=0 closingB=0 result=0 for l in expression: if l=='(': openB+=1 if l==')': closingB+=1 result=openB - closingB if result==0: return True else: return False print(balanced(input()))
3 Respostas
+ 1
Thanks mate
0
I HAVE THE EXACT SAME PROBLEM! My code is different but it solves every case except the last hidden one
text = input()
def balanced(text):
for i in text:
if text.count("(") ==text.count(")"):
return True
else:
return False
print(balanced(text))