[LeetCode][Python3] 131. Palindrome Partitioning
2019. 3. 23. 02:27 |
프로그래밍/LeetCode
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 :
전형적인 백트래킹 문제
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 264. Ugly Number II (0) | 2019.03.26 |
---|---|
[LeetCode][Python3] 334. Increasing Triplet Subsequence (0) | 2019.03.25 |
[LeetCode][Python3] 297. Serialize and Deserialize Binary Tree (0) | 2019.03.25 |
[LeetCode][Python3] 105. Construct Binary Tree from Preorder and Inorder Traversal (0) | 2019.03.24 |
[LeetCode][Python3] 128. Longest Consecutive Sequence (0) | 2019.03.23 |
[LeetCode][Python3] 42. Trapping Rain Water (0) | 2019.03.23 |
[LeetCode][Python] 341. Flatten Nested List Iterator (0) | 2019.03.22 |
[LeetCode][Python3] 200. Number of Islands (0) | 2019.02.11 |
최근에 달린 댓글 최근에 달린 댓글