```
class Solution {
public:
bool isValid(string s) {
stack<char> left;
for(int i=0; i<=s.size()-1; i++) {
if (s[i] == '(' || s[i] == '[' || s[i] == '{')
left.push(s[i]);
else {
if (left.empty()) return false;
char x = left.top();
left.pop();
if (x == '(' && s[i] != ')' || x == '{' && s[i] != '}' || x == '[' && s[i] != ']') return false;
}
}
return left.empty();
}
};
```