노력에는 지름길이 없으니까요

프로그래머스 - 예산 (Python ver.) 본문

Python/프로그래머스

프로그래머스 - 예산 (Python ver.)

데건 2024. 6. 28. 14:31
728x90

 

해결일 언어 레벨 테스트명
20240628 Python level 2  예산

 

링크 : https://school.programmers.co.kr/learn/courses/30/lessons/12982/solution_groups?language=python3

 

 


 

내 코드

def solution(d, budget):
    d.sort()
    answer=0
    for i in range(len(d)):
        budget=budget-d[i]
        if budget < 0 : break
        answer+=1
        
    return answer

 

 

 

개선점: -

 

베스트 코드

-

 

다른 풀이를 좀 살펴봤는데,

sum()을 일일이 구하는 것보다는 budget에서 빼는 쪽이

효율성 (빅오) 면에서 더 낫겠다고 한다.

O(n^2) / O(n) 정도의 차이라고...

 

알고리즘 시간복잡도 관련해서도 한 번 조사를 해야할 것 같다.

 

728x90
반응형