import java.util.*; public class Solution { /** * 最大正方形 * @param matrix char字符型二维数组 * @return int整型 */ public int solve (char[][] matrix) { // write code here int m = matrix.length; int n = matrix[0].length; int max = 0; int dp[][] = new int [m][n]; for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ dp[i][j] = matrix[i][j] - '0'; if(dp[i][j] == 1) max = 1; } } for(int i = 1; i < m; i++){ for(int j = 1; j < n; j++){ if(dp[i][j] == 1){ dp[i][j] = Math.min(Math.min(dp[i-1][j-1],dp[i][j-1]),dp[i-1][j]) + 1; max = Math.max(max,dp[i][j]); } } } return max*max; } }