Given a string containing brackets characters “(“,”)”,”[“,”]”,”{” and “}”, find out whether it has balanced brackets or not.
A string has balanced brackets if:
- Open brackets must be closed by the same type of brackets.
- Different open/close brackets should not overlapping with each other.
Sample Input:
[ { [ ] { ( ) [ ] } } ]
Sample Output:
Balanced
数据结构和算法:初级练习题 #25 – 平衡括号
给定一个字符串里面包括小括号、中括号和大括号,检测是否所有的括号都是平衡的。
如果符合下面的条件,括号就是平衡的:
- 左括号后面有相同的右括号
- 不同左右括号的顺序不能错位重叠。
输入样例:
[ { } { } ( ] )
输出样例:
Unbalanced
Python Solution