题解 | #有效括号序列#
有效括号序列
http://www.nowcoder.com/practice/37548e94a270412c8b9fb85643c8ccc2
class Solution {
public:
/**
*
* @param s string字符串
* @return bool布尔型
*/
bool isValid(string s) {
stack<char> ss;
for(int i=0; i<s.size(); i++){
if(s[i]=='(' || s[i]=='{' || s[i]=='[')
ss.push(s[i]);
else{
if(ss.empty()) return false;
if(s[i]==')' && ss.top()!='(') return false;
if(s[i]=='}' && ss.top()!='{') return false;
if(s[i]==']' && ss.top()!='[') return false;
ss.pop();
}
}// 返回值判断是否为空!!!
return ss.empty();
// write code here
}
};
https://www.cnblogs.com/grandyang/p/4424587.html

查看29道真题和解析