stack-queue-brackets
Initialize a counter variable, balance
, to 0.
(
, {
, or [
), increment balance
by 1.)
, }
, or ]
), decrement balance
by 1.
balance
becomes negative, return False
immediately since the brackets are not balanced.True
if balance
is 0, indicating that the brackets are balanced. Otherwise, return False
.balance
variable to keep track of the bracket balance.stack-queue-brackets_useing stack stack-queue-brackets_with out stack