You are viewing a single comment's thread. Return to all comments →
JavaScript Solution
function isBalanced(s) { let stack=[], top=-1, map=new Map([[')','('],['}','{'],[']','[']]) for(let i=0;i<s.length;i++){ if(/[\)\}\]]/.test(s[i])){ if(top>=0 && map.get(s[i])==stack[top] ) top-- else return "NO" } else stack[++top]=s[i] } return top>=0?"NO":"YES" }
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