최소직사각형 (프로그래머스)

Namlulu·2021년 12월 3일
0

알고리즘

목록 보기
8/28
코드를 입력하세요
function solution(sizes) {
   const newArray = []
   
   for (let size of sizes) {
       if (size[0] > size[1]) {
           newArray.push(size)
       } else {
           newArray.push([size[1], size[0]])
       }
   }
   
   const left = []
   const right = []
   
   for (let item of newArray) {
       left.push(item[0])
       right.push(item[1])
   }
    
   return Math.max(...left) * Math.max(...right)
}

=> 정렬 활용하면 더 깔끔한 코드가 나왔을 텐데.. 좀 아쉽다는 생각이 들었다..

profile
Better then yesterday

0개의 댓글