알고리즘

[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

 

chi3236/algorithm

Contribute to chi3236/algorithm development by creating an account on GitHub.

github.com