2023-04-10 20:03:58 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class Solution {
|
2024-01-03 12:06:42 +01:00
|
|
|
public:
|
|
|
|
bool isValid(const std::string &s) {
|
2023-04-10 20:03:58 +02:00
|
|
|
std::vector<char> st;
|
|
|
|
|
|
|
|
for (auto c : s) {
|
|
|
|
switch (c) {
|
|
|
|
case '(':
|
|
|
|
st.push_back(')');
|
|
|
|
break;
|
|
|
|
case '{':
|
|
|
|
st.push_back('}');
|
|
|
|
break;
|
|
|
|
case '[':
|
|
|
|
st.push_back(']');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (st.empty() || st.back() != c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
st.pop_back();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return st.empty();
|
|
|
|
}
|
|
|
|
};
|