Help me pls with "Balanced Parentheses" lesson | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help me pls with "Balanced Parentheses" lesson

I wrote that code https://code.sololearn.com/ca10a7a240A2 to complete https://www.sololearn.com/learning/eom-project/1159/1114 lesson And it works! But how can I optimize it now?

29th Jul 2021, 6:19 PM
Alexander Putintsev
Alexander Putintsev - avatar
1 Answer
0
instead of using a list and insert/pop, use an integer and increment/decrement use elif return parentheses != 0 With this optimizations it will be about 2.3 times faster (100000 entries of 256 chars) But, if you just use expr.count("(")-expr.count(")") It will get around 31 times faster
30th Jul 2021, 12:19 AM
Angelo
Angelo - avatar