标签:
突然不想解释了= =……
1 public int maximalSquare(char[][] matrix) { 2 if(matrix.length == 0 || matrix[0].length == 0) { 3 return 0; 4 } 5 int row = matrix.length; 6 int col = matrix[0].length; 7 int max = 0; 8 int[][] res = new int[row][col]; 9 for(int i = 0; i < row; i++) { 10 res[i][0] = (matrix[i][0] == ‘1‘)? 1:0; 11 if(res[i][0] > 0) { 12 max = 1; 13 } 14 } 15 for(int i = 0; i< col; i++) { 16 res[0][i] = (matrix[0][i] == ‘1‘)? 1:0; 17 if(res[0][i] > 0) { 18 max = 1; 19 } 20 } 21 for(int i = 1; i < row; i++) { 22 for(int j = 1; j < col; j++) { 23 if(matrix[i][j] == ‘1‘) { 24 res[i][j] = Math.min(Math.min(res[i-1][j], res[i-1][j-1]), res[i][j-1]) + 1; 25 if(res[i][j] > max) { 26 max = res[i][j]; 27 } 28 } 29 } 30 } 31 return max * max; 32 }
标签:
原文地址:http://www.cnblogs.com/warmland/p/5606428.html