728x90
320x100
def solution(d, budget):
result = 0
answer = 0
for i in sorted(d):
result += i
if result > budget:
return answer
answer += 1
return answer
나는 더하는 방식으로 했는데 다른 분들은 예산에서 빼는 방식으로 했더라.
(+) 다른 사람 풀이
def solution(d, budget):
answer = 0 # 가능한 부서의 수
for i in sorted(d):
budget -= i
if budget < 0:
break
answer += 1
return answer
728x90
320x100
'💻 하나씩 차곡차곡 > 프로그래머스 (Python)' 카테고리의 다른 글
[프로그래머스/python/Lv1] [1차] 비밀지도 (0) | 2023.12.21 |
---|---|
[프로그래머스/python/Lv1] 숫자 문자열과 영단어 (2) | 2023.12.20 |
[프로그래머스/python/Lv1] 3진법 뒤집기 (0) | 2023.12.18 |
[프로그래머스/python/Lv1] 부족한 금액 계산하기 (0) | 2023.12.17 |
[프로그래머스/python/Lv1] 약수의 갯수와 덧셈 (0) | 2023.12.16 |