Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Meeting Time
/* #17. Meeting Time Input is a number of meetings (start_time, end_time)。 Output is a number of time intervals (start_time, end_time), where there is no meetings. For exmaple, input is [[1, 3], [6, 7]], [[2, 4]], [[2, 3], [9, 12]] ] Output [[4, 6], [7, 9]] Leetcode 相似: Leetcode 252/253 Meeting Rooms I/II; 759. Employee Free Time */ #include <iostream> #include <vector> #include <algorithm> using namespace std; struct Interval{ int start; int end; Interval(int s, int e): start(s), end(e) {} }; void print(vector<Interval>& v){ cout << "["; for(int i =0; i<(int)v.size(); i++) cout << "[" << v[i].start << "," << v[i].end << "]"; cout << "]" << endl; } bool compare(Interval& a, Interval& b){ return a.start < b.start; } vector<Interval> getTime(vector<vector<Interval>>& v){ vector<Interval> res; vector<Interval> all; for(auto x: v){ all.insert(all.end(), x.begin(), x.end()); } sort(all.begin(), all.end(), compare); print(all); int pre = all[0].end; for(int i=1; i<(int)all.size(); i++){ if(all[i].start > pre) // found one gap { res.push_back(Interval(pre, all[i].start)); pre = all[i].end; } else{ pre = max(pre, all[i].end); } } return res; } int main() { vector<vector<Interval>> vs = {{Interval(0,1), Interval(2,3)}, {Interval(3,4),Interval(5,6)}}; vector<Interval> res = getTime(vs); print(res); return 0; }
run
|
edit
|
history
|
help
0
Test 6(2020)
lab17feb22x4B.cpp
XML parsing with regex
BFS Basic
integerDivision
without HLD range Quey can be handled by just using segment tree on the FLATTENED TREE (euler tour)
dsu on tree(264E BLOOD COUSIN RETURNS)
hilbert
PrintShape
Bad palindrom