[Algorithm] 46 week(12.12 ~ 12.17) 1/3

Dev_min·2022년 12월 12일
0

algorithm

목록 보기
147/157

최소직사각형

function solution(sizes) {
    let maxWidth = 0;
    let maxHeight = 0;
    
    const convertSizes = sizes.map(([w, h]) => {
        if(w < h){
            return [h, w];
        }
        return [w, h];
    });
    
    for(let i = 0; i < convertSizes.length; i++){
        const [w, h] = convertSizes[i];
        maxWidth = Math.max(maxWidth, w);
        maxHeight = Math.max(maxHeight, h);
    };

    
    return maxWidth * maxHeight;
}
profile
TIL record

0개의 댓글