All prompts are owned by LeetCode. To view the prompt, click the title link above.
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.
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