
링크
코딩테스트 연습 > 완전탐색 > 최소직사각형
코드
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;
}
}