[LeetCode][Python3] 131. Palindrome Partitioning

티스토리 메뉴 펼치기 댓글수0

프로그래밍/LeetCode

[LeetCode][Python3] 131. Palindrome Partitioning

snoopybox
댓글수0

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 :

전형적인 백트래킹 문제

맨위로

https://www.snoopybox.co.kr/1968

신고하기