this is a simple problem, just use Stack to save the '(''{''[' and if the next character matches the peek, return true.
public boolean isValid(String s) {
int len=s.length();
if(len==0)return true;
Stack<Character> sta = new Stack<Character>();
sta.push(s.charAt(0));
for(int i=1;i<len;i++){
char ch = s.charAt(i);
if(ch=='('||ch=='['||ch=='{') sta.push(ch);
else{
if(sta.isEmpty())return false;
char ch1=sta.peek();
if(ch==')'&&ch1=='(') sta.pop();
else if(ch==']'&&ch1=='[') sta.pop();
else if(ch=='}'&&ch1=='{') sta.pop();
else return false;
}
}
if(sta.isEmpty()) return true;
else return false;
}