131. Palindrome Partitioning

Source: Internet
Author: User

    /** 131.     Palindrome Partitioning * 2015-12-17 by Mingyang * Return all possible palindrome partitioning of S. * 1. Length standard: None (Fixed) * 2. Optional range: From start to last * 3. Go one step further: Temp joins this number, then start plus 1 indicates the next one is added * 4. Step back: Temp minus this number * 5. Special CAs E:start to the last * 6. About Repetition: none * This topic did not add the start parameter at the beginning of the first time, and each time I intercepted the useless string and continued to pass forward * but it is better to use a start index (this will not cut the string Taken to intercept)*/     PublicList<list<string>>partition (String s) {List<String> item =NewArraylist<string>(); List<List<String>> res =NewArraylist<list<string>>(); if(s = =NULL|| S.length () = = 0)            returnRes; DFS (S,0, item, RES); returnRes; }     Public voidDFS (String s,intStart, list<string> item,list<list<string>>Res) {        if(Start = =s.length ()) {Res.add (NewArraylist<string>(item)); return; }         for(inti = start; I < s.length (); i++) {String str= S.substring (Start, i + 1);//each round of Dfs comes in first to take the first number, start index, you can not stringbuffer to save            if(Ispalindrome (str)) {item.add (str); DFS (s, I+ 1, item, RES);//It takes I, so the next start index is i+1Item.remove (Item.size ()-1); }        }    }     Public Static BooleanIspalindrome (String s) {intLow = 0; intHigh = S.length ()-1;  while(Low <High ) {            if(S.charat (low)! =S.charat (high))return false; Low++; High--; }        return true; }

131. Palindrome Partitioning

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.