my following program is running in O(n^3), and always get TLE

please help me to boost it up

```
public int minPalPartition2(String s){
if(s==null) return -1;
char[] str = s.toCharArray();
int length = str.length;
int[][] minCut= new int[length][length];
boolean[][] isPal = new boolean[length][length];
for(int i=0;i<length;i++){
isPal[i][i]=true;
minCut[i][i]=0;
}
for(int i=0;i<length;i++){
for(int j=i+1;j<length;j++){
int subLength = j-i+1;
if(subLength==2)
isPal[i][j] = str[i]==str[j];
else
isPal[i][j] = (str[i]==str[j]&&isPal[i+1][j-1]);
if(isPal[i][j]==true)
minCut[j][j]=0;
else{
minCut[i][j]=Integer.MAX_VALUE;
for(int k=i;k<j;k++){
minCut[i][j]=Math.min(minCut[i][j],minCut[i][k]+1+minCut[k+1][j]);
}
}
}
}
return minCut[0][length-1];
}
```