class Solution {
public:
bool isValid(string s) {
string left="{[(",right="}])";
stack<char>st;
for(auto c:s)
{
if(left.find(c)!=string::npos)
st.push(c);
else{
if(st.empty()||st.top()!=left[right.find(c)])
return false;
st.pop();
}
}
return st.empty();
}
};
网友评论