-
위클리 챌린지 8주차: 최소직사각형코딩 테스트/Level 1 2021. 9. 27. 16:31반응형
https://programmers.co.kr/learn/courses/30/lessons/86491
파이썬
def solution(sizes): h, v = 0, 0 for a, b in sizes: if a > b: a, b = b, a if h < a: h = a if v < b: v = b return h * v
Java
class Solution { public int solution(int[][] sizes) { var max_x = 0; var max_y = 0; for (var size : sizes) { var x = size[0]; var y = size[1]; if (x > y) { x = size[1]; y = size[0]; } if (max_x < x) max_x = x; if (max_y < y) max_y = y; } return max_x * max_y; } }
class Solution { public int solution(int[][] sizes) { var max_x = 0; var max_y = 0; for (var size : sizes) { if (size[0] > size[1]) { if (max_x < size[1]) max_x = size[1]; if (max_y < size[0]) max_y = size[0]; } else { if (max_x < size[0]) max_x = size[0]; if (max_y < size[1]) max_y = size[1]; } } return max_x * max_y; } }
반응형