public:
bool isValid(string s) {
vector
for(int ii = 0; ii < s.size(); ++ii) {
switch (s[ii]) {
case '(':
case '{':
case '[': v.push_back(s[ii]); break;
case ')':
if (v.empty() || v.back() != '(') return false;
else {
v.pop_back();
break;
}
case ']':
if (v.empty() || v.back() != '[') return false;
else {
v.pop_back();
break;
}
case '}':
if (v.empty() || v.back() != '{') return false;
else {
v.pop_back();
break;
}
}
}
return v.empty();
}
};
No comments:
Post a Comment