【題目描述】
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.
給出飛機(jī)的起飛和降落時(shí)間的列表馅巷,用 interval 序列表示. 請(qǐng)計(jì)算出天上同時(shí)最多有多少架飛機(jī)仑氛?
【注】如果多架飛機(jī)降落和起飛在同一時(shí)刻,我們認(rèn)為降落有優(yōu)先權(quán)掖举。
【題目鏈接】
www.lintcode.com/en/problem/number-of-airplanes-in-the-sky/
【題目解析】
1) 將start和end時(shí)間分別保存在兩個(gè)list中朗徊,并對(duì)兩個(gè)list排序首妖。
2) 從兩個(gè)list的第一個(gè)元素開(kāi)始比較,若start小于end爷恳,則天上增加一架飛機(jī)有缆,并將start進(jìn)一位,反之則天上減少一架飛機(jī)温亲,并將end進(jìn)一位棚壁。記錄每次增加飛機(jī)后天上飛機(jī)數(shù)量的最大值。
3) 當(dāng)start遍歷完成時(shí)栈虚,返回此時(shí)最大值袖外。
【參考答案】