Simply happy, once through, time is not particularly good, I think it is ispalindrome use is the Stirngbuilder method is not the reason for the mathematical method
But very happy!!
1 PublicList<list<string>>partition (String s) {2list<list<string>> res =NewArraylist<list<string>>();3 if(s = =NULL|| S.length () = = 0) {4 returnRes;5 }6Helper (res, s, 0,NewArraylist<string>());7 returnRes;8 }9 Ten Private voidHelper (list<list<string>> Res, String s,intStart, list<string>curstr) { One intLen =s.length (); A if(Start = =Len) { -Res.add (NewArraylist<string>(CURSTR)); - return; the } - for(inti = 1; i + start <= len; i++) { -String sub = s.substring (Start, i +start); - if(Ispalindrome (sub)) { + Curstr.add (sub); -Helper (res, S, start +I, curstr); +Curstr.remove (Curstr.size ()-1); A } at } - } - - Private BooleanIspalindrome (String s) { - if(s = =NULL|| S.length () = = 0) { - return true; in } -StringBuilder SB =NewStringBuilder (s); toString rev =sb.reverse (). toString (); + returns.equals (rev.); -}
131. Palindrome Partitioning