package leetcode;

/**
 * https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses/
 */
public class Problem1190 {
    public String reverseParentheses(String s) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1190 prob = new Problem1190();
        System.out.println(prob.reverseParentheses("(abcd)")); // "dcba"
        System.out.println(prob.reverseParentheses("(u(love)i)")); // "iloveu"
        System.out.println(prob.reverseParentheses("(ed(et(oc))el)")); // "leetcode"
        System.out.println(prob.reverseParentheses("a(bcdefghijkl(mno)p)q")); // "apmnolkjihgfedcbq"
    }
}

@@ -194,35 +194,50 @@
     
-// TODO%0A        return null
+return reverseParentheses(s, new IntRef())
 ;%0A  
@@ -250,21 +250,22 @@
    p
-ublic
+rivate
  static 
 void
@@ -264,418 +264,613 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem1190 prob = new Problem1190()
+class IntRef %7B%0A        private int val
 ;%0A    
+%7D%0A%0A
     
-System.out.println(prob.reverseParentheses(%22(abcd)%22)); // %22dcba%22%0A        System.out.println(prob.reversePar
+private static String reverseParentheses(String s, IntRef index) %7B%0A        String str = %22%22;%0A        while(index.val %3C s.l
 en
+g
 th
-eses(%22(u(love)i)%22)); // %22iloveu%22%0A        System.out.println(prob.reverseParentheses(%22(ed(et(oc))el)%22)); // %22leetcode%22%0A        System.out.println(prob.reverseParentheses(%22a(bcdefghijkl(mno)p)q%22)); // %22apmnolkjihgfedcbq%22
+()) %7B%0A            int i = index.val;%0A            if (s.charAt(i) == '(') %7B%0A                index.val++;%0A                str += reverseParentheses(s, index);%0A            %7D else if (s.charAt(i) == ')') %7B%0A                index.val++;%0A                return new StringBuilder(str).reverse().toString();%0A            %7D else %7B%0A                str += s.charAt(i);%0A                index.val++;%0A            %7D%0A        %7D%0A        return str;
 %0A   

Solve problem 1190