4 ms·
)))((()(()
by nightfly 7y ago
)))((()(()
- sixstringtheory 7y agoGood edge case. I’d say to immediately return an ‘unbalanced’ result once the count goes negative.
- gerdesj 7y agoWhen I check brackets by hand or manually I do actually get my hands out and when I say open I uncurl a finger, and when I say close, I furl a finger. "Open, open, open, close, open, close, close, close". Provided I have no fingers on display at the end, then the brackets are balanced. They might not be in the right place but at least they are balanced. If I find myself starting with close then I close the lid and go and do something else. I'm sure some sort of rather cheap algorithm falls out of the above. It wont guarantee correctness in what the balanced brackets actually contain but they will at least be balanced.
- jessaustin 7y ago"never go negative"