Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Solution Review: Balanced Brackets

Sumit Rawal answered on May 16, 2023 Popularity 3/10 Helpfulness 1/10

Contents


More Related Answers

  • balanced parentheses
  • balanced brackets in c++
  • balanced parentheses checker online
  • balanced parentheses checker online
  • Exercise: Balanced Brackets
  • Determine if Brackets are Balanced
  • Algorithm check balanced parentheses

  • Solution Review: Balanced Brackets

    0

    The solution relies on the value of the check variable, which is updated in each iteration. If an opening bracket is found, check is incremented by 1. In the case of a closing bracket, check is decremented by 1.

    The logic is that check should never be negative because that would imply that somewhere in the string, there are more closing brackets than opening ones. The condition for being unbalanced is satisfied and we don’t need to check further.

    Another case is that after the loop finishes, the value of check would be 0 because the brackets match. If it’s not, the function simply returns False.

    Popularity 3/10 Helpfulness 1/10 Language python
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 16 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.