标签:als char amp style else str push pop 处理
方法:直接使用栈的数据结构对相关字符处理即可
class Solution { public: bool isValid(string s) { stack<char> st; for(int i=0; i<s.size(); ++i) { if(s[i] == ‘(‘ || s[i] == ‘{‘ || s[i] == ‘[‘) st.push(s[i]); else { if(st.empty()) return false; if(s[i] == ‘)‘ && st.top() != ‘(‘) return false; if(s[i] == ‘}‘ && st.top() != ‘{‘) return false; if(s[i] == ‘]‘ && st.top() != ‘[‘) return false; st.pop(); } } return st.empty(); } };
标签:als char amp style else str push pop 处理
原文地址:http://www.cnblogs.com/chengyuz/p/6766832.html