...

/

Solution Review: Balanced Brackets

Solution Review: Balanced Brackets

Review the solution for the "Balanced Brackets" exercise.

We'll cover the following...

Solution

Let’s explore the solution to the problem of balanced brackets.

Press + to interact
def check_balance(brackets):
check = 0
for bracket in brackets:
if bracket == '[':
check += 1
elif bracket == ']':
check -= 1
if check < 0:
break
return check == 0
bracket_string = '[[[[]]'
print(check_balance(bracket_string))
...