*[プログラマー]最大の正方形-JavaScript


📌 質問する


https://programmers.co.kr/learn/courses/30/lessons/12905

📌 に答える

// 다른 분의 풀이
function solution(board) {
    const width = board[0].length;
    const height = board.length;
    if(width === 1 || height === 1) return 1;
    
    let max = 0;
    
    for(let i = 1; i < height; i++) {
        for(let j = 1; j < width; j++) {
            if(board[i][j] === 1) {
                board[i][j] = Math.min(board[i][j-1], board[i-1][j], board[i-1][j-1]) + 1;
                if(board[i][j] > max) {
                    max = board[i][j];
                }
            }
        }
    }
    return max * max;
}
amazing ...