valid-parentheses

class Solution {
public:
    bool isValid(string s) {
        string left="{[(",right="}])";
        stackst;
        for(auto c:s)
        {
            if(left.find(c)!=string::npos)
                st.push(c);
            else{
                if(st.empty()||st.top()!=left[right.find(c)])
                    return false;
                st.pop();
            }
        }
        return st.empty();
    }
};

你可能感兴趣的:(valid-parentheses)