Lintcode391 Number of Airplanes

2017-12-24  本文已影响0人  程风破浪会有时

【题目描述】

Given an interval list which are flying and landing time of the flight. How many airplanes are on the sky at most?

Notice:If landing and flying happens at the same time, we consider landing should happen at first.

给出飞机的起飞和降落时间的列表,用 interval 序列表示. 请计算出天上同时最多有多少架飞机?

【注】如果多架飞机降落和起飞在同一时刻,我们认为降落有优先权。

【题目链接】

www.lintcode.com/en/problem/number-of-airplanes-in-the-sky/

【题目解析】

1) 将start和end时间分别保存在两个list中,并对两个list排序。

2) 从两个list的第一个元素开始比较,若start小于end,则天上增加一架飞机,并将start进一位,反之则天上减少一架飞机,并将end进一位。记录每次增加飞机后天上飞机数量的最大值。

3) 当start遍历完成时,返回此时最大值。

【参考答案】

www.jiuzhang.com/solutions/number-of-airplanes-in-the-sky/

上一篇 下一篇

猜你喜欢

热点阅读