奇怪的打印机
arr[i][j]是从i到j需要打印的次数
当字符串长度大于等于2时,判断是否两边区间字符相等arr[i]==arr[j]
class Solution { public int strangePrinter(String s) { int length = s.length(); int[][] arr = new arr[length][length]; for(int i = length - 1 ; i > 0 ; --i){ //从右向左 arr[i][i] = 1; //一个字母的话就是1 for(int j = i + 1; j<n;j++){ if(s.charAt(i)==s.charAt(j){ f[i][j] = f[i][j-1]; })else{ int max = Integer.MAX_VALUE; for(int z = i;z<j;z++){ max = Math.min(max,f[i][z]+f[z+1][j]); } f[i][j]=max; } } } return f[0][n-1]; } }
标签:打印机,int,664,arr,length,奇怪 From: https://www.cnblogs.com/leehl8016/p/17461591.html