Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Merge intervals leetcode
class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { int n=intervals.size(); vector<vector<int>>ans; if(n==0 ) { return ans; } if(n==1) { return intervals; } sort(intervals.begin(),intervals.end()); int s=intervals[0][0]; int e=intervals[0][1]; for(int i=1;i<n;i++) { int a=intervals[i][0]; int b=intervals[i][1]; if(a>=s && a<=e) { s=min(s,a); e=max(b,e); } else { vector<int>v; v.push_back(s); v.push_back(e); s=a; e=b; ans.push_back(v); } } vector<int>v; v.push_back(s); v.push_back(e); ans.push_back(v); return ans; } };
run
|
edit
|
history
|
help
0
BinTree playground
Empty C++
Longest Palindrom in String
integerDivision
VecHotel2
tree
Merge problem
LIS_NEW
MergeSort
queueLinkedlist