#include <stack>
class Solution {
public:
    /**
     * 
     * @param s string字符串 
     * @return bool布尔型
     */
    map<char,char> match;
    bool isleft(char c){
        if(c=='('||c=='['||c=='{') return true;
        return false;
    }
    bool isMatch(char c,stack<char>& help){
        if(help.empty()||help.top()!=match[c]) return false;
        help.pop();
        return true;
    }
    bool isValid(string s) {
        // write code here
        stack<char> help;
        match[')']='(';
        match[']']='[';
        match['}']='{';
        for(int i=0;i<s.length();i++){
            if(isleft(s[i])) help.push(s[i]);
            else{
                if(!isMatch(s[i],help)){
                    return false;
                }
            }
        }
        if(!help.empty()) return false;
        return true;
    }
};