m*****k 发帖数: 731 | 1 一道店面
public class RatePeriod {
private Date startDate;
private Date endDate;
private Integer nightlyRate;
/* Assume getters, setters, hashCode, equals, toString have been impl’d
. */
}
/**
Returns a flattened list of rate periods where “flattened” means that any
overlaps have been resolved by favoring the greatest nightlyRate for the
duration of the overlap.
Example:
flatten [(2015-01-01, 2015-12-31, 125), (2015-03-07, 2015-03-21, 175)]
Output:
[(2015-01-01, 2015-03-06, 125),
(2015-03-07, 2015-03-21, 175),
(2015-03-22, 2015-12-31, 125)]
Viz:
Jan 1 |------------------------------125------------------------------| Dec
31
Mar 07 |----175----| Mar 21
Output:
Jan 1 |-----125-----|----175----|----------------125------------------| Dec
31
dates may duplicate and there may be gaps as well. |
|