알고리즘/프로그래머스 문제풀이
[프로그래머스] lv.2 카펫 풀이
감자156
2023. 11. 19. 19:46
반응형
문제
https://school.programmers.co.kr/learn/courses/30/lessons/42842
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제 풀이
가능한 모든 경우의 노란 직사각형 모양을 검사함.
yw, yh를 구해서 그 넓이를 둘러싼 길이가 brown과 같으면 True 리턴.
코드
def solution(brown, yellow):
res = []
for yw in range(1, yellow+1):
yh = yellow/yw
if yh%1!=0 and yw*yh!=yellow:
continue
if (yw+yh+4)*2-4 == brown:
res = [yw+2, yh+2]
return sorted(res, reverse=True)
반응형