@@ -0,0 +1,1179 @@
+import java.io.*;%0Aimport java.util.*;%0Aimport java.text.*;%0Aimport java.math.*;%0Aimport java.util.regex.*;%0A%0Apublic class Solution %7B%0A%0A  private static final Map%3CCharacter, Character%3E validChars = populateValidChars();%0A%0A  private static Map%3CCharacter, Character%3E populateValidChars() %7B%0A    Map%3CCharacter, Character%3E map = new HashMap%3CCharacter, Character%3E();%0A    map.put('%5B', '%5D');%0A    map.put('%7B', '%7D');%0A    map.put('(', ')');%0A    return map;%0A  %7D%0A%0A  public static void main(String%5B%5D args) %7B%0A    Scanner sc = new Scanner(System.in);%0A    while(sc.hasNext())%7B%0A      String str = sc.next();%0A      System.out.println(valid(str));%0A    %7D%0A  %7D%0A%0A  public static boolean valid(String str) %7B%0A    Stack%3CCharacter%3E stack = new Stack%3CCharacter%3E();%0A%0A    for (int i = 0; i %3C str.length(); i++) %7B%0A      char c = str.charAt(i);%0A%0A      if (validChars.containsKey(c)) %7B // opening paren%0A        stack.push(c);%0A      %7D else if (validChars.containsValue(c) && !stack.empty()) %7B // closing paren%0A        char closingParen = validChars.get(stack.pop());%0A        if (c != closingParen) %7B return false; %7D%0A      %7D else %7B // invalid character%0A        return false;%0A      %7D%0A    %7D%0A%0A    return stack.empty();%0A  %7D%0A%7D%0A

solve java stack