数飞机
来源:互联网 发布:mac os 10.10 cdr下载 编辑:程序博客网 时间:2024/04/30 01:06
给出飞机的起飞和降落时间的列表,用 interval 序列表示. 请计算出天上同时最多有多少架飞机?
样例
对于每架飞机的起降时间列表:[[1,10],[2,3],[5,8],[4,7]]
, 返回3
。
注意
如果多架飞机降落和起飞在同一时刻,我们认为降落有优先权。
/** * @param intervals: An interval array * @return: Count of airplanes are in the sky. */ int countOfAirplanes(vector<Interval> &airplanes) { // write your code here int n = airplanes.size(); map<int, int> buf; set<int> value; for (int i = 0; i < n; i++) { buf[airplanes[i].start]++; buf[airplanes[i].end]--; value.insert(airplanes[i].start); value.insert(airplanes[i].end); } int sum = 0; int result = 0; for (set<int>::iterator it = value.begin(); it != value.end(); it++) { sum += buf[*it]; if (sum > result) { result = sum; } } return result; }};
0 0
- 数飞机
- LintCode-数飞机
- LintCode--数飞机
- lintcode-数飞机-391
- LintCode :数飞机
- Lintcode:数飞机
- Lintcode:数飞机
- lintcode(391)数飞机
- lintcode-数飞机
- 数飞机 -LintCode
- lintcode--数飞机
- LintCode 数飞机的两种解法
- 飞机
- 飞机
- 飞机
- 飞机
- 飞机
- LintCode --number-of-airplanes-in-the-sky(数飞机)
- mysql net start mysql 服务器名无效
- 排序_快速排序
- 360笔试题——找老乡
- POJ 3576 Hash Trie
- UVAlive 1808 Best Position(FFT)
- 数飞机
- POJ 1200 Hash
- HDU 5445 Food Problem
- ZOJ 3829 贪心
- ZOJ 3822 期望DP
- c#中利用WMI对象获取物理内存和可用内存大小信息
- 大数加法与减法
- asp.net控件
- OSX的安装心得