Problem :

https://leetcode.com/problems/palindrome-partitioning/


My Solution :

class Solution:
def partition(self, s: str) -> List[List[str]]:
ans = []

def backtrack(prefix, remain):
if not remain:
return ans.append(prefix[:])
for i in range(len(remain)):
part = remain[:i+1]
if part == part[::-1]:
prefix.append(part)
backtrack(prefix, remain[i+1:])
prefix.pop()

backtrack([], s)
return ans


Comment :

전형적인 백트래킹 문제