You are viewing a single comment's thread. Return to all comments →
javascript
function isBalanced(s) { let stack = [], brackets = { '}': '{', ']': '[', ')': '(' } for (let ch of s) { if ('{[('.includes(ch)) stack.push(ch) else { if (stack[stack.length - 1] == brackets[ch]) stack.pop() else return 'NO' } } return stack.length == 0 ? 'YES' : 'NO' }
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
javascript