You are viewing a single comment's thread. Return to all comments →
JAVASCRIPT - AP
let stack = []; let ans = "YES"; let check = (b) => { if(stack[stack.length-1]==b){ stack.pop(); return true } ans="NO"; return false; }; for(let el of s){ if(el==="{" || el==="[" || el ==="(") stack.push(el); else if(el==="}"){ if(!check("{")) return ans} else if(el==="]"){ if(!check("[")) return ans} else if(el===")"){ if(!check("(")) return ans} } if(stack.length) return "NO"; return ans;
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 - AP