교육/코테
[프로그래머스]JS 최소직사각
가이버2
2022. 5. 23. 15:50
링크 :
코딩테스트 연습 - 최소직사각형 | 프로그래머스 (programmers.co.kr)
코딩테스트 연습 - 최소직사각형
[[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
function solution(sizes) {
//정렬
for(let i=0; i<sizes.length; i++){
let left = sizes[i][0];
let right = sizes[i][1];
if(left < right){
sizes[i][0] = right;
sizes[i][1] = left;
}
}
//크기계산
let maxRight = 0;
let maxLeft = 0;
for(let i=0; i<sizes.length; i++){
if(maxRight < sizes[i][0]) maxRight = sizes[i][0];
if(maxLeft < sizes[i][1]) maxLeft = sizes[i][1];
}
return maxRight*maxLeft;
}