1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| class Solution
{
public static int solution(int [][]board)
{
if(isAllZero(board)) return 0;
int answer = 1;
for (int i = 1; i < board.length; i++) {
for (int j = 1; j < board[0].length; j++) {
if(board[i][j] == 0) continue;
board[i][j] = Math.min(Math.min(board[i - 1][j], board[i][j - 1]), board[i - 1][j - 1]) + 1;
answer = Math.max(answer, board[i][j]);
}
}
return answer * answer;
}
private static boolean isAllZero(int[][] board) {
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[0].length; j++) {
if (board[i][j] == 1) {
return false;
}
}
}
return true;
}
}
|