import java.util.*;
public class Solution { /** * * @param s string字符串 * @return bool布尔型 */ public boolean isValid (String s) { Stack stack = new Stack<>(); for(char ch : s.toCharArray()){ if(ch == '('){ stack.push(')'); }else if(ch == '['){ stack.push(']'); }else if(ch == '{'){ stack.push('}'); }else if(stack.isEmpty() || stack.pop() != ch){ return false; }
}
return stack.isEmpty();
// write code here
}
}