본문 바로가기
프로그래밍/알고리즘 & 자료구조

[프로그래머스] 최소 직사각형 with 파이썬

by Play_With 2023. 4. 21.
반응형

[프로그래머스] 최소 직사각형 with 파이썬
[프로그래머스] 최소 직사각형 with 파이썬2

 

s = [[60, 50], [30, 70], [60, 30], [80, 40]]  

## 답 : 4000

 

1. max(), min() 이용

def solution(s):
    row = []
    col = []
    for i in s:
        row.append(max(i))
        col.append(min(i))

    return max(row) * max(col)

 

2. for 반복문으로 2차원 리스트에서 값 꺼내오기

def solution2(s):
    row = 0
    col = 0
    for a, b in s:
        if a < b:
            a, b = b, a

        row = max(row, a)
        col = max(col, b)

    return row * col
반응형

댓글