Written by
최태열
on
on
[Python][프로그래머스][Level2] 카펫
[Python][프로그래머스][Level2] 카펫
코드
def solution(brown, yellow):
width=yellow
height=1
while width>=height:
if (width+2)*(height+2)-width*height==brown:
return [width+2,height+2]
else:
while width>=height:
height+=1
if yellow%(height)==0:
width=yellow//(height)
break
바깥의 갈색은 노란색을 감싸는 형태이기 때문에
갈색타일의 수는 “(노란색의 폭+2)(노란색의 높이+2) - 노란색의 수” 이다.
따라서 노란색 타일이 가로로 일렬부터 세로로 일렬까지 계산해보면서 갈색타일의 수와 비교해보면 된다.
Discussion and feedback