[DAY 28]Balanced Brackets

Sherlock Chiou
1 min readDec 3, 2019

--

[Solution] Stack

Using stack to record the brackets. Each time when we get a closing bracket we would check if the stack is empty. If not, we pop the last element of the stack and check if the popped bracket matched the closing bracket we just got. Otherwise, we would just push the bracket into the stack. In the end, if the stack is not empty means this string contains imbalanced brackets.

--

--

Sherlock Chiou
Sherlock Chiou

Written by Sherlock Chiou

Be Effective and Optimize for Learning

No responses yet