Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool correct_parentheses(std::string seq)
- {
- std::stack<char> x;
- std::map<char, char> p;
- p['('] = ')';
- p['['] = ']';
- for (auto t : seq)
- {
- if (t == '(' || t == '[')
- x.push(t);
- if (t == ')' || t == ']')
- {
- if (p[x.top()] == t)
- x.pop();
- else
- return false;
- }
- }
- return x.empty();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement