Refactor "palindrome partition".