Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.21 KB

_131. Palindrome Partitioning.md

File metadata and controls

50 lines (35 loc) · 1.21 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 30, 2024

Last updated : July 30, 2024


Related Topics : String, Dynamic Programming, Backtracking

Acceptance Rate : 70.48 %


Not the most efficient but passed with pretty average results. I'll try a more optimal solution at another time.


Solutions

Python

class Solution:
    def partition(self, s: str) -> List[List[str]]:
        if len(s) == 1 :
            return [[s]]
        
        output = []
        for i in range(1, len(s) + 1) :
            if s[0:i] == s[i-1::-1] :
                if i == len(s) :
                    output.append([s])
                    continue

                right = self.partition(s[i:])
                for r in right :
                    output.append([s[0:i]] + r)

        return output