[]
[u'a'] [u'aa']
[u'a', u'a'] [u'aa', u'b'] add to result when pos == size of noms
[u'a', u'a', u'b'] add to result == size of nums
class Solution:
# @param s, a string
# @return a list of lists of string
def isPalind(self, s):
start, end = 0, len(s) - 1
while start < end:
if s[start] != s[end]:
return False
start += 1
end -= 1
return True
def isPalindrome(self, s):
for i in range(len(s)):
if s[i] != s[len(s)-1-i]: return False
return True
def dfs(self, result, current, s, pos):
if pos == len(s):
result.append(list(current))
for i in range(pos + 1, len(s) + 1):
prefix = s[pos:i]
if self.isPalindrome(prefix):
current.append(prefix)
self.dfs(result, current, s, i)
del current[-1]
def partition(self, s):
result = []
self.dfs(result, [], s, 0)
return result