#include <stack>

class Solution {
public:
    bool isValid(string s) {
        stack<char> validator;
        for (const char& cur: s)
        {
            if (left.find(cur) != left.end())
                validator.push(cur);
            else
            {
                if (validator.empty())
                    return false;
                if (right.at(validator.top()) != cur)
                    return false;
                else
                    validator.pop();
            }
        }
        if (validator.empty())
            return true;
        else
            return false;
    }
private:
    const unordered_set<char> left {'(','[','{'};
    const unordered_map<char, char> right {{'(', ')'},{'[', ']'},{'{', '}'}};
};