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
| public class 가장큰정사각형찾기 { public static void main(String[] args) { solution(new int[][]{{0,1,1,1},{1,1,1,1},{1,1,1,1},{0,0,1,0}}); }
static int solution(int[][] board) { int answer = 0; int[][] map = 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++){ map[i+1][j+1] = board[i][j]; } } for(int i=1; i<=board.length; i++){ for(int j=1; j<=board[0].length; j++){ if(map[i][j] != 0){ map[i][j] = Math.min(Math.min(map[i-1][j], map[i][j-1]), map[i-1][j-1])+1; answer = Math.max(answer, map[i][j]); } } } System.out.println(answer); return answer*answer; } }
|