class Solution(object):
def partition(self, s):
"""
:type s: str
:rtype: List[List[str]]
"""
self.res =[]
ans = []
self.findDivide(s,ans)
print self.res
return self.res
def findDivide(self,s,ans):
if not s :
#print ans
self.res.append(ans[0:])
# print self.res
return
length = len(s)
for i in range(1,length+1):
firstDivide = s[0:i]
print firstDivide
if self.isHuiwen(firstDivide):
ans.append(firstDivide)
self.findDivide(s[i:],ans)
ans.pop()
else:
continue
def isHuiwen(self,s):
length = len(s)
if length == 1:
return True
mid = (length + 1) / 2
start = 0
end = length-1
while mid <= end:
if s[start] == s[end]:
start += 1
end -= 1
continue
else:
return False
return True
s = Solution()
sl = "efe"
s.partition(sl)
hw = "abcba"
# print s.isHuiwen(hw)