You are viewing a single comment's thread. Return to all comments →
string isBalanced(string s) { stack<char> stk; for (int i = 0 ; i<s.length(); i++) { if(!stk.empty()) { char tp =stk.top(); if( (tp == '{' && s[i] == '}')||(tp == '(' && s[i] == ')') ||( tp == '[' && s[i] == ']')) { stk.pop(); }else { stk.push(s[i]); } }else { stk.push(s[i]); } }
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 →