[프로그래머스/Java] 최소직사각형

괜찮아요?·2023년 4월 6일
0

programmers

목록 보기
22/23

링크

코딩테스트 연습 > 완전탐색 > 최소직사각형

코드

import java.util.*;

class Solution {
    public int solution(int[][] sizes) {
        int[] widths = new int[sizes.length];
        int[] heights = new int[sizes.length];
        for(int i=0; i<sizes.length; i++){
            int width = sizes[i][0];
            int height = sizes[i][1];
            if(width < height){
                int temp = width;
                width = height;
                height = temp;
            }
            widths[i] = width;
            heights[i] = height;
        }
        Arrays.sort(widths);
        Arrays.sort(heights);
        
        int maxWidth = widths[sizes.length-1];
        int maxHeight = heights[sizes.length-1];
        
        return maxWidth * maxHeight;
    }
}
profile
할 수 있어요

0개의 댓글