728x90
완전탐색으로 푸는 방법
def solution(brown, red):
for a in range(1, int(red**0.5)+1):
if not red % a:
b = red // a
if 2*a + 2*b + 4 == brown:
return [b+2, a+2]
출처:
def solution(brown, red):
for index in range(1,red+1):
if red%index == 0:
length = red//index
if (((index+2)*(length+2))-(index*length)) == brown:
return [max(index+2,length+2),min(index+2,length+2)]
방정식으로 푸는 방법
def solution(brown, red):
x = (brown + 4 + ((brown + 4)**2 - 16*(brown+red))**0.5)/4
y = (brown + red) // x
return [max(x,y), min(x,y)]
출처:
728x90
'Algorithm' 카테고리의 다른 글
[프로그래머스] 쿼드압축 후 개수 세기 파이썬 (0) | 2021.03.15 |
---|---|
[프로그래머스] 타겟 넘버 (BFS/DFS) 파이썬 (0) | 2021.03.15 |
[프로그래머스] H-index 파이썬 (0) | 2021.03.11 |
[프로그래머스] 전화번호 목록 파이썬 Hash (0) | 2021.03.11 |
[프로그래머스] 가장 큰 수 파이썬 (0) | 2021.03.11 |
댓글