public static int minimumTotalCost(int[] departures, int[] returns, int minGap) {
int res = Integer.MAX_VALUE;
int minDeparture = Integer.MAX_VALUE;
for (int R = minGap; R < departures.length; R++) {
minDeparture = Math.min(minDeparture, departures[R - minGap]);
res = Math.min(res, returns[R] + minDeparture);
}
return res == Integer.MAX_VALUE ? -1 : res;
}
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎