You are viewing a single comment's thread. Return to all comments →
Java 8
public static void main(String []argh) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String input=sc.next(); StringBuilder sb = new StringBuilder(input); for(int i=0; i<sb.length(); i++) { if(i - 1 >= 0) { if((sb.charAt(i) == '}' && sb.charAt(i - 1) == '{') || (sb.charAt(i) == ']' && sb.charAt(i - 1) == '[') || (sb.charAt(i) == ')' && sb.charAt(i - 1) == '(')) { sb.deleteCharAt(i); sb.deleteCharAt(i-1); i = 0; } } } System.out.println(sb.toString().isEmpty()); } sc.close(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Stack
You are viewing a single comment's thread. Return to all comments →
Java 8