一、题目
二、代码
class Solution
{
List<List<String>> re_list = new LinkedList<>();
LinkedList<String> temp_list = new LinkedList<>();
public boolean whether(String cur )
{
int i;
char[] temp = cur.toCharArray();
int length = temp.length;
for(i=0;i<length/2;i++)
{
if(temp[i] != temp[length-1-i]) return false;
}
return true;
}
public void back(String cur, int start)
{
int i;
int length = cur.length();
if(start>cur.length()) return ;
if(start == cur.length())
{
int temp_length = temp_list.size();
for(i=0;i<temp_length;i++)
{
if(whether(temp_list.get(i)) == false) return;
}
re_list.add(new LinkedList<>(temp_list));
}
for(i=start+1;i<=length;i++)
{
temp_list.add(cur.substring(start,i));
back(cur,i);
temp_list.removeLast();
}
}
public List<List<String>> partition(String s)
{
back(s,0);
return re_list;
}
}
三、运行结果