일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 리얼 클래스
- 쓰릴오브파이트
- 프로젝트
- 매일
- leetcode
- 링피트
- 읽기
- 파비최
- FIT XR
- 사이드
- Problem Solving
- 미드시청
- 스탭퍼
- 괜찮음
- 뭐든
- 30분
- Writing
- realclass
- 잡생각
- English
- 만화도
- 10분
- 화상영어
- 영어원서읽기
- Daily Challenge
- 3줄정리
- 운동
- 월간
- 개발자
- 영어공부
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