class Solution {
List<List<String>> answer=new ArrayList<>();
List<String> path=new ArrayList<>();
public List<List<String>> partition(String s) {
if(s.length()==0) return answer;
dfs(s,0);
return answer;
}
public boolean is_Palindrome(String s,int start,int end){
for(int i=start,j=end;i<j;i++,j--){
if(s.charAt(i)!=s.charAt(j))
return false;
}
return true;
}
public void dfs(String s,int startindex){
if(startindex==s.length()){
answer.add(new ArrayList<String>(path));
return;
}
for(int i=startindex;i<s.length();i++){
if(is_Palindrome(s,startindex,i)){
String str=s.substring(startindex,i+1);
path.add(str);
}
else continue;
dfs(s,i+1);
path.remove(path.size()-1);
}
}
}