https://school.programmers.co.kr/learn/courses/30/lessons/12905#
풀이방법이 생각나지 않아서 풀이를 찾아보고 이해해서 풀었다
이차원배열을 하나더 만들고 이중 for문을 돌면서 다음과 같이 처리한다.
현재원소 값 = 현재원소 위, 왼쪽, 위왼쪽의 원소중 최소값+1 으로 갱신한다
현재원소의 위쪽 왼쪽이 범위를 벗어난경우는 현재원소 값 = 1로 처리했다
import java.util.*;
class Solution
{
public int solution(int [][]board)
{
int answer = 0;
int row = board.length;
int col = board[0].length;
int[][] mat = new int[row][col];
int max = 0;
for(int i = 0; i < row; ++i)
{
for(int j = 0; j < col; ++j)
{
if(board[i][j] == 0)
continue;
if(i == 0 || j == 0)
{
mat[i][j] = 1;
max = Math.max(max, mat[i][j]);
//System.out.print(mat[i][j]);
}
else
{
mat[i][j] = Math.min(Math.min(mat[i-1][j], mat[i][j-1]), mat[i-1][j-1]) + 1;
//System.out.print(mat[i][j]);
max = Math.max(max, mat[i][j]);
}
}
//System.out.println();
}
answer = max*max;
return answer;
}
}