[프로그래머스/파이썬] Level 1 예산

bye9·2021년 4월 20일
0

알고리즘(코테)

목록 보기
116/130

https://programmers.co.kr/learn/courses/30/lessons/12982


문제풀이

금액을 오름차순으로 정렬하고 하나씩 더해가 budget과 비교했다.

소스코드

def solution(d, budget):
    d.sort()

    cnt=0
    tmp=0
    for i in d:
        tmp+=i
        if tmp<=budget:
            cnt+=1
        else:
            break
    return cnt

0개의 댓글