728x90
def solution(max_weight, specs, names):
answer = []
answer.append(None)
print(answer)
specs = dict(specs)
# print(specs)
tmp = 0
cnt = 1
for n in names:
tmp += int(specs[n])
if tmp > max_weight:
cnt += 1
tmp = int(specs[n])
# print(tmp, cnt)
return cnt
처음에 pseudo 코드로 만들고 풀었을때
에러가 났던 부분은
if 문에서
tmp를 int(specs[n])이 아니라 0로 설정해서 안풀렸다
tmp에 새로운 무게를 추가했을때, max_weight을 초과하게 되면
tmp는 추가한 무게로 초기화 시켜주는 것이 중요했다.(0이 아니라)
그리고 cnt는 1부터 시작해야 한다는 점을 틀렸었다.
728x90
'DC 2' 카테고리의 다른 글
[자료구조] 사탕 담기 파이썬 (0) | 2021.04.20 |
---|---|
[자료구조] 카펫 파이썬 (0) | 2021.04.20 |
[자료구조] 나머지 한 점 파이썬 (0) | 2021.04.20 |
[자료구조] 스택 파이썬(LeetCode, Programmers) (0) | 2021.04.20 |
[자료구조] Doubly Linked List 구현 (0) | 2021.04.20 |
댓글