LeetCode20. 有效的括号
https://leetcode-cn.com/problems/valid-parentheses/
class Solution {
public:
bool isValid(string s) {
stack<char>sta;
for (auto x : s) {
if (sta.empty()) {
sta.push(x);
continue;
}
if ((sta.top() == '(' && x == ')')
|| (sta.top() == '[' && x == ']')
|| (sta.top() == '{' && x == '}'))
sta.pop();
else sta.push(x);
}
return sta.empty();
}
};