有效括号序列
public boolean isValid (String s) {
// write code here
Stack<Character> stack=new Stack<Character>();
for (int i=0;i<s.length();i++){
if(s.charAt(i)=='(') stack.push(')');
else if(s.charAt(i)=='[') stack.push(']');
else if(s.charAt(i)=='{') stack.push('}');
else {
if(stack.isEmpty()) return false;
char c=stack.pop();
if(c!=s.charAt(i)) return false;
}
}
if(stack.isEmpty()) return true;
else {
return false;
}
}