Preview:
class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        sort(intervals.begin(),intervals.end());
        
        int n=intervals.size();
         vector<vector<int>> vns;
        vector<int> v1=intervals[0];
        for(int i=1;i<n;i++)
        {
            if(v1[1]<intervals[i][0])
            {
                vns.push_back(v1);
                v1=intervals[i];
            }
            else 
            {
                v1[1]=max(v1[1],intervals[i][1]);
            }
        }
        vns.push_back(v1);
        return vns;
    }
};
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter