We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Using a stack is unnecessary. We can simply match pairs of brackets using Regex and remove them from the string until the string is gone. If we ever don't find a match or if the string length is not an even number we can return 'NO'
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
Using a stack is unnecessary. We can simply match pairs of brackets using Regex and remove them from the string until the string is gone. If we ever don't find a match or if the string length is not an even number we can return 'NO'
Here's a Javascript solution: