lintcdoe: Number of Airplanes in the Sky
来源:互联网 发布:linux系统查看ip地址 编辑:程序博客网 时间:2024/06/10 09:47
Number of Airplanes in the Sky
30:00
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.
For interval list [[1,10],[2,3],[5,8],[4,7]]
, return 3
/** * Definition of Interval: * classs Interval { * int start, end; * Interval(int start, int end) { * this->start = start; * this->end = end; * } */class Solution {public: /** * @param intervals: An interval array * @return: Count of airplanes are in the sky. */ int countOfAirplanes(vector<Interval> &airplanes) { // write your code here vector<int> departure; vector<int> landing; for (int i=0; i< airplanes.size(); i++) { departure.push_back(airplanes[i].start); landing.push_back(airplanes[i].end); } sort(departure.begin(), departure.end()); sort(landing.begin(), landing.end()); int airplane_in_sky = 1; int most_airplane_in_sky = 1; int i=1; int j=0; //因为首先要有一只飞机在天上飞,所以i要先于j while (i < departure.size() && j < landing.size()) { if (departure[i] < landing[j]) { airplane_in_sky++; if (airplane_in_sky > most_airplane_in_sky) { most_airplane_in_sky = airplane_in_sky; } i++; } else { airplane_in_sky--; j++; } } return most_airplane_in_sky; }};
0 0
- lintcdoe: Number of Airplanes in the Sky
- lintcode:Number of Airplanes in the Sky
- [LintCode]Number of Airplanes in the Sky
- LintCode --number-of-airplanes-in-the-sky(数飞机)
- LintCode Number of Airplanes in the Sky(Java)
- [lintcode] - 391 Number of Airplanes in the Sky
- 391.Number of Airplanes in the Sky-数飞机(中等题)
- PIE IN THE SKY
- The Scar of the Sky
- Sky number
- The sky in my heart is raining...
- count the number of "1" in the binary figure
- Invalid update: invalid number of rows in section 0. The number of rows contained in an ....
- 'Invalid update: invalid number of sections. The number of sections contained in the table view aft
- Increasing the maximum number of tcp/ip connections in linux
- Reducing the Number of Gray Levels in an Image
- Compute the sum number in PIC() clause of COBOL
- SGU 407-Number of Paths in the Empire【DP】
- POJ 3746 Teacher YYF(恶心+打表)
- Leetcode ☞ 217. Contains Duplicate
- 安卓第四天笔记-Sqlite
- LightOJ 1065 Number Sequence(矩阵快速幂)
- TCP/IP各层协议介绍
- lintcdoe: Number of Airplanes in the Sky
- 计蒜客 挑战难题 批量替换字符串
- Selenium的API介绍
- notepad快速解决一个小问题
- 短信还原的注意点
- VB.net 监视Windows剪切板中数据变化
- 看JDBC轻松连接数据库,你值得拥有
- 前端面试题
- 构造哈弗曼树