| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 | 31 |
Tags
- FIT XR
- 사이드
- 월간
- 3줄정리
- 영어공부
- English
- 10분
- 쓰릴오브파이트
- 프로젝트
- 미드시청
- 스탭퍼
- 잡생각
- Problem Solving
- 뭐든
- realclass
- Daily Challenge
- 화상영어
- 30분
- 리얼 클래스
- 괜찮음
- 읽기
- leetcode
- 파비최
- 개발자
- 매일
- 링피트
- 운동
- Writing
- 만화도
- 영어원서읽기
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.28 Today's Challenge 본문
https://leetcode.com/problems/minimum-cost-for-tickets
Minimum Cost For Tickets - LeetCode
Can you solve this real interview question? Minimum Cost For Tickets - You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array days. Each day is an integer from 1 to 365. Train
leetcode.com
DP 로 푸는 문제. DFS/BFS에서 DP 나오는걸로 바뀐 듯 ㅋㅋ
class Solution:
def mincostTickets(self, days: List[int], costs: List[int]) -> int:
dayset = set(days)
durations = [1, 7, 30]
@lru_cache(None)
def dp(i):
if i > 365:
return 0
elif i in dayset:
return min(dp(i+d) + c for c, d in zip(costs, durations))
else:
return dp(i+1)
return dp(1)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.03.30 Today's Challenge (0) | 2023.03.30 |
|---|---|
| 2023.03.29 Today's Challenge (0) | 2023.03.29 |
| 2023.03.27 Today's Challenge (0) | 2023.03.27 |
| 2023.03.26 Today's Challenge (0) | 2023.03.26 |
| 2023.03.25 Today's Challenge (0) | 2023.03.25 |
Comments