Given A string s, partition s such that every substring of the partition are a palindrome.
Return the minimum cuts needed for a palindrome partitioning of s.
For example, given s = "aab" ,
Return 1 since the palindrome partitioning ["aa","b"] could be produced using 1 cut.
First DP Find all the sub-palindrome string stored in F, and then use the array h to record the minimum number of partitions in a position, is also the DP
public class Solution {Boolean F[][];int res = integer.max_value;int h[];p ublic int mincut (String s) {f = new Boolean[s.le Ngth ()][s.length ()];for (int i = 0; i < s.length (); i++) {f[i][i] = true;} int maxlen = 1;for (int i = 0; i < s.length ()-1; i++) {if (S.charat (i) = = S.charat (i + 1)) {f[i][i + 1] = True;maxlen = 2;}} for (int len = 3; Len <= s.length (), len++) {Boolean in = false;for (int i = 0; i < s.length ()-len + 1; i++) {if ( S.charat (i) = = S.charat (i + len-1) && f[i + 1][i + len-2]) {f[i][i + len-1] = True;in = true;}} if (in) {maxlen = Len;}} if (MaxLen = = S.length ()) return 0;h = new Int[s.length () +1];h[0] = -1;for (int i=1;i<=s.length (); i++) {H[i] = Integer.max _value;for (int j=1;j<=i;j++) {if (F[j-1][i-1]&&h[j-1]!=integer.max_value) {H[i] = Math.min (H[i], h[j-1]+1) ;}}} Return H[s.length ()];}}
[Leetcode] Palindrome Partitioning II