Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You can reduce the checks by both changing the second if to elif, and by indenting the third if to be part of the elif chr == ")" block (The only circumstance in which cnt will become negative will be if you've just encountered a close paren.
In the original solution, there are 3 checks for each character. I agree with milesb.
I don't think you're right. In order to do what you say, you would have to do at least one check (char == ")") for every character, two checks if the character turns out to actually be ")".
So your total number of checks would be [number of characters in the string] + [number of ")" in the string]... while in the original solution it was only [number of characters in the string]
This comment is hidden because it contains spoiler information about the solution