Page tree
Skip to end of metadata
Go to start of metadata
class Solution:
    def partition(self, s: str) -> List[List[str]]:
        result = []

        def dfs(index, path):
            if index == len(s):
                result.append(path)
                return

            for i in range(index, len(s)):
                sub = s[index:i + 1]
                if sub == sub[::-1]:
                    dfs(i + 1, path + [sub])
        dfs(0, [])

        return result
  • No labels