天天看点

leetcode题目:Palindrome Partitioning 和Palindrome Partitioning II

题目一:

Given a string s, partition s such that every substring of the partition is a palindrome.

Return all possible palindrome partitioning of s.

For example, given s = <code>"aab"</code>,

Return

解题思路:

1)用一个二维数组来存取两者之间是否是回文。

2)从字符串尾部开始存入可能的回文串。

代码:

题目二:

Return the minimum cuts needed for a palindrome partitioning of s.

Return <code>1</code> since the palindrome partitioning <code>["aa","b"]</code> could

be produced using 1 cut.

1)用二维数组存入判断两者之间是否是回文。

2)同时用一个一维数组存取从这个点开始往右的最小切数。