Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example, given s ="aab",
Return
[ ["aa","b"], ["a","a","b"]]
def dfs(S, path, res): if len(S) < 1: res.append(path[:]) return i = 0 while i < len(S): begin = 0 end = i while begin < end: if S[begin] == S[end]: begin += 1 end -= 1 else: break if begin >= end: path.append(S[0:i+1]) dfs(S[i+1:],path,res) path.pop() i = i + 1 def partition(S): res = [] path = [] dfs(S, path, res) return res print partition("aba")