Deduplication character string (not preserved repeated characters)

/ **
     * removed repeating characters (not preserved repeated characters)
     * @param original string S
     * @return to the weight of string
     * /
    public static String Remove (String S) {
        // string into array
        char [] s.toCharArray = SS ();
        // identifier (continued determines whether duplicate)
        Boolean = in Flag to false;
        // character received after the deduplication
        the StringBuffer the StringBuffer new new SB = ();
        // start determination
        do {
            // each before the start times of the cycle identification reset to false
            In Flag to false =;
            // empty string receiving
            SB = the StringBuffer new new ();
            // identification (if there is repeated characters)
            Boolean = n-to false;
            // Find the cycle is repeated characters
            for (int I = 0; I <ss.length; I ++) {
                // character duplicate
                the while (I <ss.length -. 1 && SS [I] == SS [I +. 1]) {
                    // subscript + . 1
                    I ++;
                    // the end of the cycle is determined to continue the next cycle is repeated characters
                    In Flag = to true;
                    // character duplicate
                    n-= to true;
                }
                // duplicate character
                if (n) {
                    // after a repeated start character
                    ++ I;
                    // reset identifying
                    n-= to false;
                }
                // re-splicing to character
                sb.append (SS [I]);
            }
            // Array reassigned
            SS = sb.toString () toCharArray ();.
        } The while (In Flag);
        
        return sb.toString ();
        
    }

Guess you like

Origin blog.csdn.net/qq_36161345/article/details/83025682