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 bbaf8ed commit 23dabe3Copy full SHA for 23dabe3
Algorithms/Medium/983_MinimumCostForTickets/Solution.java
@@ -0,0 +1,31 @@
1
+class Solution {
2
+ int[] memo = new int[400];
3
+
4
+ public int solve(int i, int[] days, int[] costs) {
5
+ if (i >= days.length) {
6
+ return 0;
7
+ }
8
9
+ if (memo[i] > 0) {
10
+ return memo[i];
11
12
13
+ memo[i] = 1000000;
14
+ for (int j = 0; j < 3; j++) {
15
+ int next = days[i] + ((j == 0) ? 1 : ((j == 1) ? 7: 30));
16
+ int k = i;
17
18
+ while (k < days.length && days[k] < next) {
19
+ k++;
20
21
22
+ memo[i] = Math.min(memo[i], costs[j] + solve(k, days, costs));
23
24
25
26
27
28
+ public int mincostTickets(int[] days, int[] costs) {
29
+ return solve(0, days, costs);
30
31
+}
0 commit comments