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?
1 Resposta
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