You are viewing a single comment's thread. Return to all comments →
JavaScript Solution:-
function isBalanced(s) { let stack = []; let matchingBrackets = { '(': ')', '{': '}', '[': ']' }; for (let char of s) { if (matchingBrackets[char]) { stack.push(char); } else { let top = stack.pop(); if (matchingBrackets[top] !== char) { 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 Solution:-