Skip to content

Commit

Permalink
dp
Browse files Browse the repository at this point in the history
  • Loading branch information
SamirPaulb committed Apr 4, 2022
1 parent 1fa96c0 commit 8f564ca
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# https://leetcode.com/problems/minimum-cost-for-tickets/

class Solution:
def mincostTickets(self, days: List[int], costs: List[int]) -> int:
n = max(days) + 1
dp = [-1 for x in range(n)]
#dp = [-1]*(max(days)+1)
dp[0] = 0

for x in range(1,len(dp)):
if x in days:
if x>=30:
#print(x,min(dp[x-1]+costs[0],dp[x-7]+costs[1],dp[x-30]+costs[2]))
dp[x] = min(dp[x-1]+costs[0],dp[x-7]+costs[1],dp[x-30]+costs[2])

elif x>=7 and x<30:
dp[x] = min(dp[x-1]+costs[0],dp[x-7]+costs[1],costs[2])

else:
dp[x] = min(dp[x-1]+costs[0],costs[1],costs[2])

else:
dp[x] = dp[x-1]

return dp[max(days)]

0 comments on commit 8f564ca

Please sign in to comment.