Re:A Brutal Look at Balanced Parentheses, Computing Machines...
by braythwayt on Friday February 22, 2019 @02:25PM
(#19228284)
The stack solution checks that the stack is non-empty before popping.
The counter solution simply needs to check that the counter is non-zero before decrementing.
All cases then work perfectly.
EDIT: yep, after reading the comments below I see that I really should have put just a little more thought before dismissing this as too trivial to think about.