@@ -0,0 +1,1019 @@
+/*%0AGiven a string containing just the characters '(', ')', '%7B', '%7D', '%5B' and '%5D', determine if the input string is valid.%0A%0AThe brackets must close in the correct order, %22()%22 and %22()%5B%5D%7B%7D%22 are all valid but %22(%5D%22 and %22(%5B)%5D%22 are not.%0A*/%0A%0Aimport java.io.*;%0Aimport java.util.*;%0A%0Apublic class ValidParentheses %7B%0A%09public static boolean isValid(String s) %7B%0A%09%09Stack%3CCharacter%3E stack = new Stack%3CCharacter%3E();%0A%09%09for(int i = 0; i%3Cs.length(); i++) %7B%0A%09%09%09if(s.charAt(i) == '(' %7C%7C s.charAt(i) == '%5B' %7C%7C s.charAt(i) == '%7B')%0A%09%09%09%09stack.push(s.charAt(i));%0A%09%09%09else if(s.charAt(i) == ')' && !stack.empty() && stack.peek() == '(')%0A%09%09%09%09stack.pop();%0A%09%09%09else if(s.charAt(i) == '%5D' && !stack.empty() && stack.peek() == '%5B')%0A%09%09%09%09stack.pop();%0A%09%09%09else if(s.charAt(i) == '%7D' && !stack.empty() && stack.peek() == '%7B')%0A%09%09%09%09stack.pop();%0A%09%09%09else%0A%09%09%09%09return false;%0A%09%09%7D%0A%09%09return stack.empty();%0A%09%7D%0A    %0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09String s = %22%7B%7B((%5B%5D))%7D%7D%22;%0A%09%09boolean r = isValid(s);%0A%09%09System.out.println(s + %22 valid? %22 + r);%0A%09%09return;%0A%09%7D%09%0A%7D%0A

valid parentheses