Skip to main content

983. Minimum Cost For Tickets - LeetCode

class Solution:
def mincostTickets(self, days: list[int], costs: list[int]) -> int:
day_costs = dict(zip([1, 7, 30], costs))
N = days[-1]
dp = [0] * (N + 1)
travel = set(days)
for i in range(1, N + 1):
if i in travel:
dp[i] = min(dp[max(0, i - d)] + c for d, c in day_costs.items())
else:
dp[i] = dp[i - 1]
return dp[-1]