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