알고리즘
[Programmers]최소 직사각형(난이도:★★★★)
BaekGyuHyeon
2022. 5. 16. 19:43
https://programmers.co.kr/learn/courses/30/lessons/86491
코딩테스트 연습 - 최소직사각형
[[10, 7], [12, 3], [8, 15], [14, 7], [5, 15]] 120 [[14, 4], [19, 6], [6, 16], [18, 7], [7, 11]] 133
programmers.co.kr
class Solution {
public int solution(int[][] sizes) {
// 세로로 긴 명함은 가로로 돌리기
for(int i = 0 ;i < sizes.length; i++){
if(sizes[i][0] < sizes[i][1]){
int tmp = sizes[i][0];
sizes[i][0] = sizes[i][1];
sizes[i][1] = tmp;
}
}
int width = 0;
int height = 0;
// 최댓값 구하기
for(int[] i : sizes){
width = Math.max(width,i[0]);
height = Math.max(height,i[1]);
}
return width * height;
}
}