diff --git a/LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py b/LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py new file mode 100644 index 00000000..082dd2ec --- /dev/null +++ b/LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py @@ -0,0 +1,19 @@ +class Solution: + def mincostTickets(self, days, costs): + n = len(days) + if(n == 1): + return min(costs) + + dp = [0]*(n+1) + + for i in range(n): + + ans = dp[i] + costs[0] + j = i + for c, d in zip(costs[1:], [7, 30]): + while j >= 0 and days[j] > days[i]-d: + j -= 1 + ans = min(ans, dp[j+1] + c) + dp[i+1] = ans + + return dp[n] \ No newline at end of file