🧠𝗔𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺/💙프로그래머스

[위클리챌린지] 8주차 최소직사각형(JavaScript)

안오늘 2021. 9. 29. 11:00

문제

https://programmers.co.kr/learn/courses/30/lessons/86491

 

풀이

function solution(sizes) {
    let answer = 0;
    // 두 변중 긴 것 -> 가로
    // 두 변중 짧은 것 -> 세로
    let width = 0;
    let height = 0;
    for (let i = 0; i < sizes.length; i++) {
        width = Math.max(width, Math.max(sizes[i][0], sizes[i][1]));
        height = Math.max(height, Math.min(sizes[i][0], sizes[i][1]));
    }
    answer = width * height;
    return answer;
}