Advertisement
ogv

Untitled

ogv
Oct 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. class Solution {
  2. public int mincostTickets(int[] days, int[] costs) {
  3. int ix = 0;
  4.  
  5. int[] len = { 1, 3, 7 };
  6. int[] last = { -1, -1, -1 };
  7. int[] costX = { -1, -1, -1 };
  8. int min = -1;
  9.  
  10. for (int i = 1; i <= 365 && ix < days.length; i++) {
  11. for (int j = 0; j < 3; j++)
  12. if (last[j] != -1 && i >= last[j] + len[j]) last[j] = -1;
  13.  
  14. if (i != days[ix]) continue;
  15.  
  16. System.out.print("before i = " + i + ", last= ");
  17. for (int j = 0; j < 3; j++ ) System.out.print(last[j] + " ");
  18. System.out.print(", costX= ");
  19. for (int j = 0; j < 3; j++ ) System.out.print(costX[j] + " ");
  20. System.out.println(", min = " + min);
  21.  
  22. for (int j = 0; j < 3; j++)
  23. if (last[j] == -1) {
  24. costX[j] = min != -1 ? min + costs[j]: costs[j];
  25. last[j] = i;
  26. }
  27.  
  28. min = costX[0];
  29. for (int j = 1; j < 3; j++)
  30. if (costX[j] < min) min = costX[j];
  31.  
  32. System.out.print("after i = " + i + ", last= ");
  33. for (int j = 0; j < 3; j++ ) System.out.print(last[j] + " ");
  34. System.out.print(", costX= ");
  35. for (int j = 0; j < 3; j++ ) System.out.print(costX[j] + " ");
  36. System.out.println(", min = " + min);
  37.  
  38. ix++;
  39. }
  40.  
  41. return min;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement