Written by
java-style
on
on
위클리 챌린지 - 최소직사각형 (Java, Javascript)
위클리 챌린지 - 최소직사각형 (Java, Javascript)
반응형
Java
import java.util.Arrays; class Solution { public int solution(int[][] sizes) { int width = 0; int height = 0; for(int[] size : sizes) { Arrays.sort(size); width = Math.max(width, size[0]); height = Math.max(height, size[1]); } return width*height; } }
Javascript
function solution(sizes) { let width = 0; let height = 0; sizes.map(([w,h]) => w > h ? [w,h] : [h,w]) .forEach(size => { width = Math.max(width, size[0]); height = Math.max(height, size[1]); }); return width * height; }
반응형
from http://namcoding.tistory.com/18 by ccl(S) rewrite - 2021-11-19 05:28:17