current position:Home>Force deduction 221 question maximum square

Force deduction 221 question maximum square

2022-02-03 00:49:33 CSDN Q & A

img


int solve(int[][] matrix) {
int[][] a = new int[matrix.length][matrix[0].length];
int max = 0;
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] == 0) continue;
if (i == 0 || j == 0 || matrix[i - 1][j - 1] == 0) a[i][j] = 1;
else {
a[i][j] = a[i - 1][j - 1] + 1;
for (int k = 1; k <= a[i - 1][j - 1]; k++) {
if (matrix[i - k][j] == 0 || matrix[i][j - k] == 0) {
a[i][j] = k;
break;
}
}
}
if (a[i][j] > max) max = a[i][j];
}
}
return max;
}
Kind people look at where the compilation error is




Refer to the answer 1:

The brackets are wrong , Delete the closing parentheses and try




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030049317780.html

Random recommended