Exercise: Balanced Brackets
Let's check if the brackets in a string are balanced.
We'll cover the following
Problem Statement
Given a string containing only square brackets, []
, you must check whether the brackets are balanced or not. The brackets are said to be balanced if, for every opening bracket, there is a closing bracket after it.
You will write your code in the check_balance()
function, which returns True
if the brackets are balanced and False
if they are not.
For an empty string, the function will return True
.
For the sake of simplicity, you can assume that the string will not contain any other characters.
Get hands-on with 1200+ tech skills courses.