Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int mincostTickets(int[] days, int[] costs) {
- int ix = 0;
- int[] len = { 1, 3, 7 };
- int[] last = { -1, -1, -1 };
- int[] costX = { -1, -1, -1 };
- int min = -1;
- for (int i = 1; i <= 365 && ix < days.length; i++) {
- for (int j = 0; j < 3; j++)
- if (last[j] != -1 && i >= last[j] + len[j]) last[j] = -1;
- if (i != days[ix]) continue;
- System.out.print("before i = " + i + ", last= ");
- for (int j = 0; j < 3; j++ ) System.out.print(last[j] + " ");
- System.out.print(", costX= ");
- for (int j = 0; j < 3; j++ ) System.out.print(costX[j] + " ");
- System.out.println(", min = " + min);
- for (int j = 0; j < 3; j++)
- if (last[j] == -1) {
- costX[j] = min != -1 ? min + costs[j]: costs[j];
- last[j] = i;
- }
- min = costX[0];
- for (int j = 1; j < 3; j++)
- if (costX[j] < min) min = costX[j];
- System.out.print("after i = " + i + ", last= ");
- for (int j = 0; j < 3; j++ ) System.out.print(last[j] + " ");
- System.out.print(", costX= ");
- for (int j = 0; j < 3; j++ ) System.out.print(costX[j] + " ");
- System.out.println(", min = " + min);
- ix++;
- }
- return min;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement