public class Solution { public IList> Partition(string s) { if(string.IsNullOrEmpty(s)) { return new List >(); } var result = new List >(); Travel(s, 0, new List () , ref result); return result; } private void Travel(string s , int start, IList current, ref List > result) { if(start == s.Length) { result.Add(new List (current)); return; } for(var i = start + 1; i <= s.Length; i++) { var x = s.Substring(start, i - start); if(IsP(x)){ current.Add(x); Travel(s, i , current, ref result); current.RemoveAt(current.Count - 1); } } } private bool IsP(string s) { if(s.Length == 1){ return true; } var len = s.Length % 2 == 0 ? s.Length / 2 : (s.Length - 1) / 2; for(var i = 0;i < len; i++){ if(s[i] != s[s.Length - 1- i]){ return false; } } return true; } }