[프로그래머스] 가장 큰 정사각형

2020. 4. 7. 14:45프로그래머스/LEVEL 2

import java.util.*;

class Solution
{
    public int solution(int [][]board)
    {
        int answer = 0;

        int[][] copy = new int[board.length+1][board[0].length+1];
        
        for(int i=0; i<board.length; i++){
            for(int j=0; j<board[0].length; j++){
                copy[i+1][j+1] = board[i][j];
            }
        }
       
        for(int i=1; i<copy.length; i++){
            for(int j=1; j<copy[0].length; j++){
                
                if(copy[i][j]==1){
               int temp = Math.min(Math.min(copy[i][j-1],copy[i-1][j]),copy[i-1][j-1]);
               
                copy[i][j] = temp+1;
                answer = Math.max(copy[i][j],answer);
                }
            }
            
        }
        
        answer = (int) Math.pow(answer,2);
            
        return answer;
    }
}

참고 : https://programmers.co.kr/learn/courses/18/lessons/847