Recursive implementation of a "recurring character" in the removal string

Source: Internet
Author: User

The string you'll 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 is 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'll change the string as follows: "AYQQYJJJ", "AYYJJJ", AJ JJ "," AJ ".
Return the resulting string

1  Public classdigui{2     Static Private intT=0;3     Static Private intLen;4     Static PrivateString S;5      Public Static voidFintN) {6t++;7          while(T<len&&s.charat (n)!=s.charat (n+1))8F (n+1);9         if(T==len)return;Ten         Else{     OneS=s.substring (0,n) +s.substring (n+2, S.length ()); At++; -         } -     } the     Private StaticString Eraser () { -len=s.length (); -         if(len!=0) F (0); -         returns;  +     } -      Public Static voidMain (string[] args) { +S= "ADDAEFG"; A System.out.println (Eraser ()); at     } -}

Recursive implementation of a "recurring character" in the removal string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.