Algorithms / Programmers / 카펫

Onam Kwon·2022년 4월 21일
0

Algorithms

목록 보기
13/24

링크

https://programmers.co.kr/learn/courses/30/lessons/42842

풀이

  • brown = 2width + 2height - 4
  • yellow = widthxheight - 2width - 2height + 4

코드

def solution(brown, yellow):
    sum = brown + yellow
    # exhaustive search
    for height in range(1, sum+1):
        if (sum%height)==0:
            width = sum/height
            if width>=height and brown==2*width+2*height-4:
                return [width, height]
profile
권오남 / Onam Kwon

0개의 댓글