๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/12938
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 3๋จ๊ณ - ์ต๊ณ ์ ์งํฉ
def solution(n, s):
answer = []
if s < n: return [-1]
for i in range(n):
answer.append(s//n)
idx = len(answer) - 1
for j in range(s % n):
answer[idx] += 1
idx -= 1
return answer
print(solution(2,9))
์งํฉ์ ๊ณฑ์ด ์ต๋๊ฐ ๋๋ ค๋ฉด ๊ฐ๊ฐ์ ์ซ์์ ์ฐจ์ด๊ฐ ์ต์๊ฐ ๋์ด์ผ ํ๋ค.
๋ฐ๋ผ์ s ๋ฅผ n์ผ๋ก ๋๋ ๊ฐ์ ๋ฆฌ์คํธ์ ์ถ๊ฐํด ์ค๋ค. ๊ทธ ํ ๋๋จธ์ง๋ฅผ ๋ค์ ์ธ๋ฑ์ค๋ถํฐ 1์ฉ ์ถ๊ฐํด ์ฃผ๋๋ก ํ๋ค.
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โฌ [Programmers] [Python] [Level2] ํ ์ธ ํ์ฌ (0) | 2023.04.10 |
---|---|
โฌ [Programmers] [Python] [Level2] ํผ๋ก๋ (0) | 2023.04.06 |
โฌ [Programmers] [Python] Level2_์ฐ์ ๋ถ๋ถ ์์ด ํฉ์ ๊ฐ์ (0) | 2023.04.06 |
โฌ [Programmers] [Python] Level2_์์ฅ (0) | 2023.04.06 |
โฌ [Programmers] [Python] Level2_๊ทค ๊ณ ๋ฅด๊ธฐ (0) | 2023.04.06 |