-----QUESTION------
Given a string
Return the minimum cuts needed for a palindrome partitioning of
For example, given "aab"
,
Return 1
["aa","b"]
-----SOLUTION------
class Solution {
public:
int minCut(string s) {
int sLength = s.length();
vector<vector<bool>> flag(sLength,vector<bool>(sLength, false));
int cut[sLength];
cut[0]=0;
for (int i=1;i<sLength;i++)
{
cut[i]=1+cut[i-1];
for(int j=0;j<i;j++)
if(s[i]==s[j]&&(i-j<=2||flag[j+1][i-1]))
{
flag[j][i]=true;
if(j==0)
{
cut[i] = 0;
break;
}
else cut[i] = min(cut[i],1+cut[j-1]);
}
}
return cut[sLength-1];
}
};