How to do balanced parentheses? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

How to do balanced parentheses?

I tried this - worked on all the test cases but test 3 which is hidden - thanks in advance def balanced(expression): #your code goes here stack = [] for b in expression: if b == "(": stack.insert(0, b) if b == ")" and len(stack) > 0: stack.pop() return len(stack) == 0 print(balanced(input()))

1st Oct 2021, 7:48 PM
Jess
Jess - avatar
3 ответов
0
If for ex: input is ) or )() return true but it shoud be false
1st Oct 2021, 7:56 PM
Jayakrishna 🇮🇳
0
Thank you!
1st Oct 2021, 8:05 PM
Jess
Jess - avatar
0
someone give me the answer please?
17th Jun 2022, 1:02 PM
Valentin Quijano
Valentin Quijano - avatar