Valid Parentheses
/* 判断括号匹配问题,用一个栈保存判断即可 */ class Solution { public: bool isValid(string s) { int len = s.length(); stack<char>s1; for(int i = 0 ; i < len ; i++){ if(s[i] == '(') s1.push(')'); else if(s[i] == '[') s1.push(']'); else if(s[i] == '{') s1.push('}'); else if(!s1.empty() && s1.top() == s[i]){ s1.pop(); }else return false; } if(s1.empty()){ return true; } return false; } };