#include <cstring>
#include <stack>
class Solution {
  public:

    stack<char>  C_stack;
    bool isValid(string s) {
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '(' || s[i] == '{' || s[i] == '[') {
                C_stack.push(s[i]);
            } else {
                 if(!C_stack.empty()){
                    char temp_char=C_stack.top();
                    C_stack.pop();
                    if(s[i]==')'){
                        if(temp_char!='(')
                          return false;
                    }

                    if(s[i]==']'){
                        if(temp_char!='[')
                          return false;
                    }

                    if(s[i]=='}'){
                        if(temp_char!='{')
                          return false;
                    }

                  }else {
                     return false;
                  }
                }
        }


        if(C_stack.empty()){
            return true;
        }else {
           return false;
        }
            }
} ;