[프로그래머스]level1-운송 트럭-Python[파이썬]

s2ul3·2022년 9월 21일
0


나의 풀이

def solution(max_weight, specs, names):
    spec_dict = dict() # (물건이름 : 무게)를 담는 딕셔너리
    for spec in specs:
        s_name, s_weight = spec
        spec_dict[s_name] = int(s_weight)
    total = 0 # 트럭 하나에 들어가는 물건들의 무게합
    cnt = 1
    for name in names:
        total += spec_dict[name]
        if total > max_weight: 
            cnt += 1 # 트럭 하나가 더 필요함
            total = spec_dict[name]
    return cnt
profile
statistics & computer science

0개의 댓글