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