Refactor PalindromePartition