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