You are viewing a single comment's thread. Return to all comments →
JS
function isBalanced(s) { const len = s.length - 1 const open = ["(", "{", "["] const close = [")", "}", "]"] const queue = [] for (let i = 0; i <= len; i++) { if (open.includes(s[i])) { queue.unshift(open.indexOf(s[i])) continue } if (queue[0] == close.indexOf(s[i])) { queue.splice(0, 1) continue } return "NO" } if (queue.length == 0){ return "YES" } else { return "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 →
JS