#C12091. Balanced Brackets
Balanced Brackets
Balanced Brackets
The problem is to determine if the brackets in a given string are balanced. You are given a string s
which consists solely of the characters '(', ')', '{', '}', '[' and ']'. A string is called balanced if:
- Every opening bracket has a corresponding closing bracket.
- The pairs of brackets are properly nested.
In mathematical terms, if we denote an opening bracket by its corresponding symbol and a closing bracket by its partner, then for all brackets the following condition must hold:
$$ \text{For every substring } s', \quad \#\text{(opening brackets)} = \#\text{(closing brackets)} $$
Your task is to check if the input string is balanced.
inputFormat
The input consists of a single line which is the string s
containing only the characters '(', ')', '{', '}', '[' and ']'.
outputFormat
Output a single line: True
if the string is balanced, and False
otherwise.
True