class Solution {
public boolean isValid(String s) {
Stack<Character> stack = new Stack<>();
char[] chs = s.toCharArray();
int len = chs.length;
if((len&1)==1)return false;
for(int i=0;i<len;i++){
if(stack.isEmpty()||!isMatch(stack.peek(),chs[i]))
stack.push(chs[i]);
else
stack.pop();
}
return stack.isEmpty();
}
public boolean isMatch(char a,char b){
switch(a){
case '(': if(b == ')') return true; else return false;
case '{': if(b == '}') return true; else return false;
case '[': if(b == ']') return true; else return false;
default : return false;
}
}
}