class Solution { public: /** * * @param s string字符串 * @return bool布尔型 */ bool isValid(string s) { // write code here stackstack1; stack1.push('s'); int len=s.size(); for(int i=0;i<len;i++) { char c=s[i]; if(c=='('||c=='['||c=='{'){ stack1.push(c); continue; } if(c==')'||c==']'||c=='}'){ if(c==')') if(stack1.top()!='(') return false; else stack1.pop(); if(c==']') if(stack1.top()!='[') return false; else stack1.pop(); if(c=='}') if(stack1.top()!='{') return false; else stack1.pop(); } } if(stack1.size()!=1) return false; return true; } };