class Solution {
public:
bool isValid(string s) {
if(s.length()%2!=0) return false;
stack<char> left;
unordered_map<char,char> pei;
pei['('] = ')';
pei['['] = ']';
pei['{'] = '}';
for(int i=0; i<s.length(); i++){
if(s[i]=='('||s[i]=='['||s[i]=='{') left.push(s[i]);
else
if(left.empty()) return false;
if(s[i]==pei[left.top()]) left.pop();
}
if(left.size()>0) return false;
return true;
}
};
思路是对的,但是几个特殊的地方没注意到,比如( (( }}
最后一种情况直接判断空,就能解决