How to implement Palindrome Partitioning in LeetCode problem 131?