Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solução em Python3 da questão 983 - Minimum Cost For Tickets #66

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions python/983_Minimum_Cost_For_Tickets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def mincostTickets(self, days: List[int], costs: List[int]) -> int:
@functools.lru_cache(None)
def dp(i, cost_cover_till_day):

if i >= len(days):
return 0

if days[i] <= cost_cover_till_day:
return dp(i+1, cost_cover_till_day)
else:
one_day_cost = costs[0] + dp(i+1, days[i])
seven_day_cost = costs[1] + dp(i+1, days[i]+6)
thirty_day_cost = costs[2] + dp(i+1, days[i]+29)

return min(one_day_cost, seven_day_cost, thirty_day_cost)


return dp(0, 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line at the end