You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
map<char,char> closing; // the set of closing parenthesis
closing[')'] = '('; // the opening parenthesis of the closing parenthesis
closing[']'] = '[';
closing['}'] = '{';
stack<char> stack;
map<char,char>::iterator it;
for (int i = 0; i < s.size(); i++) {
it = closing.find(s[i]);
if (it != closing.end()) // if s[i] is found in closing
if (!stack.empty() && it->second == stack.top()) // if stack is not empty and its top element is the opening parenthesis of the closing parenthesis s[i]
stack.pop();
else
return false;
else
stack.push(s[i]); // add the opening s[i] to stack