@@ -0,0 +1,1590 @@
+// Runtime: 0 ms, faster than 100.00%25 of Java online submissions.%0A// Memory Usage: 37.5 MB, less than 100.00%25 of Java online submissions.%0A//%0A// Input string always contains a valid matching set of parentheses.%0A//%0A// Time complexity is O(n * s) where n is the number of characters and s is the number of sets of%0A// parentheses.%0A// Space complexity is O(n) where n is the length of the input string.%0A//%0A// Test cases:%0A// %22(abcd)%22%0A// %22(u(love)i)%22%0A// %22(ed(et(oc))el)%22%0A// %22a(bcdefghijkl(mno)p)q%22%0A// %22abc%22%0A// %22ta()usw((((a))))%22%0A// %22a(fgh)b(d(iotp)e)c%22%0A//%0Aclass Solution %7B%0A  public String reverseParentheses(String s) %7B%0A    if (s == null) return s;%0A%0A    char%5B%5D arr = new char%5Bs.length()%5D; // array to swap characters%0A    for (int i = 0; i %3C s.length(); i++) %7B%0A      arr%5Bi%5D = s.charAt(i);%0A    %7D%0A%0A    // Update the stack or swap between matching brackets%0A    int%5B%5D open = new int%5Barr.length%5D; // stack for open brackets%0A    int oi = 0;%0A    for (int i = 0; i %3C arr.length; i++) %7B%0A      if (arr%5Bi%5D == '(') %7B%0A        open%5Boi++%5D = i;%0A      %7D else if (arr%5Bi%5D == ')') %7B%0A        swap(arr, open%5B--oi%5D + 1, i - 1);%0A      %7D%0A    %7D%0A%0A    // Construct result%0A    StringBuilder sb = new StringBuilder();%0A    for (int i = 0; i %3C arr.length; i++) %7B%0A      if (arr%5Bi%5D != '(' && arr%5Bi%5D != ')') %7B%0A        sb.append(arr%5Bi%5D);%0A      %7D%0A    %7D%0A    return sb.toString();%0A  %7D%0A%0A  // Swaps elements in 'arr' between 'start' and 'end'%0A  private void swap(char%5B%5D arr, int start, int end) %7B%0A    while (start %3C end) %7B%0A      char t = arr%5Bstart%5D;%0A      arr%5Bstart%5D = arr%5Bend%5D;%0A      arr%5Bend%5D = t;%0A      start++;%0A      end--;%0A    %7D%0A  %7D%0A%7D%0A

add solution