Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Lv. 1
- LEVEL 2
- select
- programmers
- DP
- join
- 오블완
- 너비 우선 탐색
- bfs
- Python
- group by
- softeer
- 자바스크립트
- 티스토리챌린지
- Dynamic Programming
- 파이썬
- 깊이 우선 탐색
- Java
- Baekjoon
- 소프티어
- 동적계획법
- Lv. 2
- SQL 고득점 KIT
- javascript
- level 3
- dfs
- SQL
- 프로그래머스
- Lv. 3
- Lv. 0
Archives
- Today
- Total
몸과 마음이 건전한 SW 개발자
프로그래머스 Lv2 택배 배달과 수거하기 Python 본문
정답 코드
def solution(cap, n, deliveries, pickups):
trunk = [0, 0]
distance = 0
for idx in range(n-1, -1, -1):
trunk[0] += deliveries[idx]
trunk[1] += pickups[idx]
while trunk[0] > 0 or trunk[1] > 0:
trunk[0] -= cap
trunk[1] -= cap
distance += (idx + 1) * 2
return distance
느낀점
- 접근 방식은 비슷했는데 그동안 while문의 실행 조건에 대해서 잘 이해하지 못했던 것 같다.
- while문은 조건에 맞으면 실행하는데 위의 방식은 외우는게 좋을 것 같다.
- 그리디인가?
'알고리즘' 카테고리의 다른 글
프로그래머스 Lv2 순위 검색 Python (2) | 2023.09.11 |
---|---|
프로그래머스 Lv2 양궁대회 Python (0) | 2023.09.10 |
프로그래머스 Lv.3 [2023 KAKAO BLIND RECRUITMENT] 미로 탈출 명령어 Python (0) | 2023.09.01 |
Softeer level3 [HSAT 5회 정기 코딩 인증평가 기출] 성적 평가 Python (0) | 2023.08.29 |
Softeer level3 우물 안 개구리 Python (0) | 2023.08.28 |