We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Same concept, but with some performance enhancements:
functionisBalanced(s){// concept: must come out in same orderconstmap={'[':']','(':')','{':'}'},tracker=[]for(leti=0;i<s.length;++i){constc=s[i]switch(c){case'[':case'(':case'{':tracker.push(map[s[i]])breakcase']':case')':case'}':if(tracker.pop()!=c){return'NO'}}}returntracker.length==0?'YES':'NO'}
Cookie support is required to access HackerRank
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 →
Good job!
Same concept, but with some performance enhancements: