We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 75d2bff commit e44dba4Copy full SHA for e44dba4
leetcode/cpp/dynamic programming/983.cpp
@@ -0,0 +1,23 @@
1
+class Solution {
2
+public:
3
+ int mincostTickets(vector<int>& days, vector<int>& costs) {
4
+ int n_days = (int)days.size();
5
+ int last_day = days[n_days - 1];
6
+ vector<int> cost(last_day + 1,0);
7
+ int j = 0;
8
+ int z = 0;
9
+ for(int i = 1; i <= last_day; i++){
10
+ if(days[j] == i){
11
+ j++;
12
+ int a = INT_MAX, b = INT_MAX, c = INT_MAX;
13
+ a = cost[i - 1] + costs[0];
14
+ b = cost[max(z, i - 7)] + costs[1];
15
+ c = cost[max(z, i - 30)] + costs[2];
16
+ cost[i] = min({a, b, c});
17
+ }
18
+ else cost[i] = cost[i-1];
19
20
+
21
+ return cost[last_day];
22
23
+};
0 commit comments