class Solution {
public:
bool isValid(string s) {
stack<char>st;
for (auto x : s) {
if (st.empty()) {
st.push(x);
continue;
}
if ((st.top() == '[' && x == ']') || (st.top() == '(' && x == ')') ||
(st.top() == '{' && x == '}'))st.pop();
else st.push(x);
}
return st.empty();
}
};

京公网安备 11010502036488号