You are viewing a single comment's thread. Return to all comments →
string isBalanced(string s) { unordered_map<char, char> map = { {'(', ')'}, {'{', '}'}, {'[', ']'} }; stack<char> sc; for (char c : s) { if (map.count(c)) sc.push(map[c]); else { if (sc.empty() || sc.top() != c) return "NO"; sc.pop(); } } return (sc.empty()) ? "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 →