有效的括号

class Solution {
public:
    bool isValid(string s) {
        if(s.size()==0) return true;

        map<char,char> hash={ {')','('}, {'}','{'}, {']','['} };

        stack<int> st;
        for(int i=0;i<s.size();i++){
            if(s[i]=='(' || s[i]=='[' || s[i]=='{'){
                st.push(s[i]);
            }
            else{
                if(st.empty()){ return false;}
                else{
                    if(st.top()==hash[s[i]]){
                        st.pop();
                    }
                    else{
                        return false;
                    }
                }
            }
        }

        return st.empty();
    }
};
原文地址:https://www.cnblogs.com/zijidan/p/12435579.html