import java.util.*;

public class Solution { /** * * @param s string字符串 * @return bool布尔型 */ public static boolean isValid (String s) { ArrayList a = new ArrayList(); a.add("()"); a.add("{}"); a.add("[]"); LinkedList t1 = new LinkedList<>(); for(int i=0;i<s.length();i++){ if (t1.size()>0){ String k = t1.getLast()+s.charAt(i); if (a.contains(k)){ t1.removeLast(); } else{ t1.add(""+s.charAt(i)); } } else{ t1.add(""+s.charAt(i)); } } if (t1.size()==0){ return true; } return false; } }