Ad
  • Custom User Avatar

    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.

  • Default User Avatar

    In the original solution, there are 3 checks for each character. I agree with milesb.

  • Custom User Avatar

    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]

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution