Balanced Parentheses
Check if the expression has properly nested brackets.
{
[
(
)
]
}
Empty
StackStatus: Ready
Speed
Algorithm Logic
1function isBalanced(s):
2 stack = []
3 for char in s:
4 if char in "({[":
5 stack.push(char)
6 else:
7 if stack.empty or !match(stack.top, char):
8 return false
9 stack.pop()
10 return stack.empty