class Solution {
public:
    /**
     *
     * @param s string字符串
     * @return bool布尔型
     */
    bool isValid(string s) {
        // write code here
        vector<char> mStack;
        for (int i = 0; i < s.size(); i++) {
            char c = s[i];
            switch (c) {
                case '(':
                    mStack.push_back(c);
                    break;
                case '[':
                    mStack.push_back(c);
                    break;
                case '{':
                    mStack.push_back(c);
                    break;
                case ')':
                    if(mStack.empty() || mStack.back() !='('){
                        return false;
                    }
                    mStack.pop_back();
                    break;
                case ']':
                    if(mStack.empty() || mStack.back() !='['){
                        return false;
                    }
                    mStack.pop_back();
                    break;
                case '}':
                    if(mStack.empty() || mStack.back() !='{'){
                        return false;
                    }
                    mStack.pop_back();
                    break;
                default:
                    break;
            }
        }
        
        return mStack.empty();
    }
};