批量建站怎么赚钱,宁波高等级公路建设指挥部网站,wordpress首页文件夹,网页设计收费标准给定一个字符串 s#xff0c;将 s 分割成一些子串#xff0c;使每个子串都是回文串。
返回 s 所有可能的分割方案。
示例:
输入: “aab” 输出: [ [“aa”,“b”], [“a”,“a”,“b”] ]
代码
class Solution {ListListString stringListnew ArrayList…给定一个字符串 s将 s 分割成一些子串使每个子串都是回文串。
返回 s 所有可能的分割方案。
示例:
输入: “aab” 输出: [ [“aa”,“b”], [“a”,“a”,“b”] ]
代码
class Solution {ListListString stringListnew ArrayList();public ListListString partition(String s) {parti(s,0,new ArrayList());return stringList;}public boolean isPartition(String s) {//判断回文StringBuilder stringBuildernew StringBuilder(s);stringBuilder.reverse();return stringBuilder.toString().equals(s);}public void parti(String s,int pos,ListString temp) {if(poss.length()) //边界{stringList.add(new ArrayList(temp));return;}for(int len1;lenposs.length();len){String subs.substring(pos,poslen);if(isPartition(sub)){temp.add(sub);parti(s,poslen,temp);temp.remove(temp.size()-1);。。回溯}}}
}