How can I optimize this algorithm to reverse strings inside parentheses?
String reverseParentheses(String s) {
String tmpCh = new String("");
String tmpChRe = new String("");
String tmp = new String("");
int l = s.length();
int n = 0;
int j =0;
for(int i = 0;i<l;i++){
if(s.charAt(i)=='(')
n++;
}
int T[] = new int[n];
for(int i=0;i<l;i++){
if(s.charAt(i)=='('){
T[j]=i;
j++;
}
}
j=0;
while(n>0){
j = T[n-1] + 1;
while(s.charAt(j)!=')'){
tmpCh = tmpCh + s.charAt(j);
j++;
}
for(int q=tmpCh.length()-1;q>=0;q--)
tmpChRe = tmpChRe + tmpCh.charAt(q);
tmp = s.substring(0,T[n-1]) + tmpChRe + s.substring(T[n-1]+tmpChRe.length()+2);
s = tmp;
n--;
tmp = "";
tmpCh = "";
tmpChRe = "";
}
return s ;
}