You are viewing a single comment's thread. Return to all comments →
//JS Solution function isBalanced(s) { let brackDict = [ ["(",")"], ["[","]"], ["{","}"], ]; let stack = []; for (let i = 0; i < s.length; i++) { let match = brackDict.find(item => item[0] == s[i]); if (match) { stack.push(match); } else { let last = stack.pop(); if (last == undefined || last[1] != s[i]) { return 'NO'; } } } if (stack.length != 0) { return 'NO'; } return '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 →