class Solution {
public int solution(int [][]board) {
int answer = 0;
int[][] dp = new int[board.length][board[0].length];
for(int i=0; i<dp.length; i++) {
for(int j=0; j<dp[0].length; j++) { dp[i][j] = board[i][j]; }
}
for(int i=1; i<dp.length; i++) {
for(int j=1; j<dp[0].length; j++) {
if(dp[i][j]==0) { continue; }
if(dp[i-1][j-1]>0 && dp[i][j-1]>0 && dp[i-1][j]>0) {
dp[i][j] = Math.min(Math.min(dp[i][j-1], dp[i-1][j]), dp[i-1][j-1])+1;
}
}
}
for(int i=0; i<dp.length; i++ ) {
for(int j=0; j<dp[0].length; j++) { answer = Math.max(answer, dp[i][j]); }
}
return answer*answer;
}
}
'Problem Solving > Programmers' 카테고리의 다른 글
[Level 2] 올바른 괄호 (0) | 2022.04.07 |
---|---|
[Level 2] [3차] 파일명 정렬 (0) | 2022.04.07 |
[Level 2] 방문 길이 (0) | 2022.04.07 |
[Level 2] 스킬트리 (0) | 2022.04.07 |
[Level 2] n^2 배열 자르기 (0) | 2022.04.07 |