From b7b92af2769e59b1069bfe8b5bc7cf96626475e6 Mon Sep 17 00:00:00 2001 From: ist187644 Date: Sat, 23 Oct 2021 11:23:41 +0100 Subject: [PATCH 1/2] Added solution for 983. Minimum Cost For Tickets Leetcode problem --- .../Python/983_Minimum_Cost_For_Tickets.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py 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..1786b81f --- /dev/null +++ b/LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py @@ -0,0 +1,19 @@ +class Solution: + def mincostTickets(self, days: List[int], costs: List[int]) -> int: + 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 From 6d719028ac9f4e2865721b8a6b4f2f3544622d9e Mon Sep 17 00:00:00 2001 From: ist187644 Date: Sat, 23 Oct 2021 11:25:20 +0100 Subject: [PATCH 2/2] Cleared unnecessary strongly typed arguments --- LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py b/LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py index 1786b81f..082dd2ec 100644 --- a/LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py +++ b/LeetCode/Problems/Python/983_Minimum_Cost_For_Tickets.py @@ -1,5 +1,5 @@ class Solution: - def mincostTickets(self, days: List[int], costs: List[int]) -> int: + def mincostTickets(self, days, costs): n = len(days) if(n == 1): return min(costs)