반응형
https://programmers.co.kr/learn/courses/30/lessons/42842?language=python3
1. 갈색의 개수 = 2 * (가로+세로-2)
2. 노란색의 개수 = (가로-2) * (세로-2)
1번식을 재조합하면,
(가로+세로) = (갈색의 개수) / 2 + 2
이때, 가로가 세로보다 길거나 같다고 가정했으므로 가로를 (갈색의 개수) / 2 + 2로, 세로를 0으로 세팅한 뒤
2번식을 만족할 때까지 값을 하나씩 늘리고 빼준다.
def solution(brown, yellow):
width = brown/2+2
height = 0
while (width-2)*(height-2) != yellow:
width -= 1
height += 1
return [width, height]
반응형
'Online-Judge > Programmers' 카테고리의 다른 글
[Programmers] Python 짝지어 제거하기 (0) | 2022.06.18 |
---|---|
[Programmers] Python 숫자 문자열과 영단어 (0) | 2022.06.18 |
[Programmers] Python K번째수 (0) | 2022.06.15 |
[Programmers] Python 완주하지 못한 선수 (0) | 2022.06.14 |
[Programmers] Python JadenCase 문자열 만들기 (0) | 2022.06.14 |
댓글