class Solution { public: bool isValid(string s) { stack<char> str; for(int i=0;i<s.size();i++) if(s[i]==')' || s[i]==']' || s[i]=='}'){ if(str.empty()) return false; else{ char c=str.top(); str.pop(); if(c=='('&&s[i]!=')' || c=='['&&s[i]!=']' || c=='{'&&s[i]!='}') return false; } }else str.push(s[i]); return str.empty(); } };