import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return bool布尔型
*/
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() || s.charAt(i) != stack.pop()){
return false;
}
}
return stack.isEmpty();
}
}