把时间看过一个数轴,然后合并重复的时间,但是没有排序,没有官方答案的简洁!
官方答案:
排序算法很值得学习!
We read the list of times,sort it by start time,and then walk over the list once,merging overlapping times. Then we walk the list watching for long milking periods and long non-milking periods.
An alternate approach would be to just keep an array of size a million and mark off times. On a nice fast processor,that's probably fast enough,but our above algorithm will work even on slow processors,and it's not much harder to write.
原文链接:https://www.f2er.com/vb/262223.html