递归实现一个去除字符串中“重复出现的字符”

The string you will received as a parameter has too many characters. Your job is to
remove characters from the string in the following order:
    1.    Find the smallest i such that the i-th character and the (i+1)-th character of the string are same.
    2.    If there is no such i, end the process.
    3.    Remove the i-th and the (i+1)-th character of the string, and repeat from 1.
  
For example, if the parameter is "ayqqyjjj", she will change the string as follows: "ayqqyjjj " -> " ayyjjj " -> "ajjj" -> "aj".
 Return the resulting string

 1 public class digui{
 2     static private int t=0;
 3     static private int len;
 4     static private String s;
 5     public static void f(int n){
 6         t++;
 7         while(t<len&&s.charAt(n)!=s.charAt(n+1))
 8             f(n+1);
 9         if(t==len) return;
10         else{    
11             s=s.substring(0,n)+s.substring(n+2,s.length());
12             t++;
13         }
14     }
15     private static String Eraser(){
16         len=s.length();
17         if(len!=0)    f(0);
18         return s;    
19     }
20     public static void main(String[] args){
21         s="addaefg";
22         System.out.println(Eraser());
23     }
24 }
原文地址:https://www.cnblogs.com/qq1029579233/p/4411150.html