문제
![](https://velog.velcdn.com/images/cosmos/post/c4e90656-c670-47e1-888d-d11e9b168cc0/image.png)
풀이
- 주어진 사각형의 가로, 세로 중 큰 값을 가로로, 작은 값을 세로로 재정렬 한 뒤, 2중 list에서 가장 큰 가로값과 세로값을 곱하면 답을 도출해 낼 수 있다.
코드
def solution(sizes: list) -> int:
rearrange, max_x, max_y = [], 0, 0
for size in sizes:
if size[0] >= size[1]:
rearrange.append([size[0], size[1]])
else:
rearrange.append([size[1], size[0]])
for x in rearrange:
max_x, max_y = max(x[0], max_x), max(x[1], max_y)
return max_x * max_y
if __name__ == '__main__':
print(solution([[60, 50], [30, 70], [60, 30], [80, 40]]))
print(solution([[10, 7], [12, 3], [8, 15], [14, 7], [5, 15]]))
print(solution([[14, 4], [19, 6], [6, 16], [18, 7], [7, 11]]))
결과
![](https://velog.velcdn.com/images/cosmos/post/abd82a26-ac64-4500-9933-a31f8176135d/image.png)
출처 & 깃허브
programmers 최소직사각형
github