classSolution: defpartition(self, s: str) -> List[List[str]]: path,result = [],[] defsymmetric_str(path) -> bool: # 判断是否为回文串; is_or_not = True for num in path: left,right = 0,len(num)-1 while left<=right and num[left]==num[right]: left += 1 right -= 1 if left <= right: is_or_not = is_or_not andFalse return is_or_not defsplit_tree(s,start_index): # 用 分叉树的回溯,解决 组合、分割。 if start_index>=len(s): if symmetric_str(path): result.append(path.copy()) return for i inrange(start_index,len(s)): path.append(s[start_index:i+1]) split_tree(s,i+1) path.pop() return result return split_tree(s,0)