Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Interview Prep
bool cmp(vector<int> a,vector<int> b) { return a[0]<=b[0]; } class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { int i; int n=intervals.size(); vector<vector<int>> ans; if(n==0) return ans; sort(intervals.begin(),intervals.end(),cmp); for(i=1;i<n;i++) { if(intervals[i][0]<=intervals[i-1][1]) { intervals[i][0]=intervals[i-1][0]; intervals[i][1]=max(intervals[i][1],intervals[i-1][1]); } } int a=intervals[0][0]; int b=intervals[0][1]; for(i=1;i<n;i++) { if(intervals[i][0]==a) b=intervals[i][1]; else { ans.push_back(vector<int>({a,b})); a=intervals[i][0]; b=intervals[i][1]; } } ans.push_back(vector<int>({a,b})); return ans; } };
run
|
edit
|
history
|
help
0
BinSearch
RuntimeError
Primality Test | Fermat
Motsow
abbinsertbool
Weighted Average
Merge intervals leetcode
Sieve Of Eratosthenes
thread
alm7ly