class Solution {
public:
bool isValid(string s) {
stack<char> stack;
for (int i = 0; i < s.size(); i ++) {
if (s[i] == ')' || s[i] =='}' || s[i] == ']') {
if (stack.empty()) return false;
char temp = stack.top();
stack.pop();
if (s[i] == ')' && temp != '(') return false;
else if (s[i] == '}' && temp != '{') return false;
else if (s[i] == ']' && temp != '[') return false;
}
else stack.push(s[i]);
}
return stack.empty();
}
};
标签:return,temp,20,括号,&&,false,stack,else,LeetCode
From: https://www.cnblogs.com/hjy94wo/p/16629809.html