Last active
November 17, 2019 07:07
-
-
Save inspirit941/01264674665fede55d0bce13e82ca706 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(n, s): | |
# 자연수 n개의 합으로 n보다 작은 s를 만들 수는 없으므로 [-1]을 리턴한다 | |
if n > s: return [-1] | |
result = [] | |
# s를 n으로 나눈 몫이 n개이도록 초기값을 정한다. | |
initial = s // n | |
for _ in range(n): | |
result.append(initial) | |
idx = len(result) - 1 | |
# s를 n으로 나눈 몫에서 나머지만큼 각 값에 1씩 더해준다. | |
for _ in range(s % n): | |
result[idx] += 1 | |
idx -=1 | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment