从分割开始,这里的判断条件不是path了,是start和s的长度了,而且是append一串字符串了,比如append(s[start:i+1])
class Solution(object):
def partition(self, s):
"""
:type s: str
:rtype: List[List[str]]
"""
def backtracking(path, start):
if start == len(s): # 从分割开始,这里的判断条件不是path了,是start和s的长度了
res.append(path[:])
else:
for i in range(start, n):
if s[start:i+1] == s[start:i+1][::-1]:
path.append(s[start:i+1])
backtracking(path, i+1)
path.pop()
n = len(s)
res = []
backtracking([], 0)
return res