-
[LeetCode] Palindrome Partitioning알고리즘 2019. 12. 7. 15:57
문제
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
Example:
Input: "aab" Output: [ ["aa","b"], ["a","a","b"] ]
Approach
DFS로 string을 i글자씩 잘라가며 palindrome인지 확인한 후
palindrome이면 자르고 남은 string을 재귀함수를 통해 다시 잘라 확인하여
최종적으로 자른게 모두 palindrome이면 답 배열에 추가한다.
Code
https://github.com/chi3236/algorithm/blob/master/LeetCode_PalindromePartitioning.cpp
'알고리즘' 카테고리의 다른 글
[LeetCode] Copy List with Random Pointer (0) 2019.12.18 [LeetCode] Gas Station (0) 2019.12.13 [LeetCode] Surrounded Regions (0) 2019.12.07 [LeetCode] Longest Consecutive Sequence (0) 2019.12.06 [LeetCode] Single Number (0) 2019.12.06