/**
* Definition for an interval.
* struct Interval {
* int start;
* int end;
* Interval() : start(0), end(0) {}
* Interval(int s, int e) : start(s), end(e) {}
* };
*/
class Solution
{
public:
static bool cmp(Interval &a,Interval &b)
{
return a.start < b.start;
}
vector<Interval> merge(vector<Interval>& intervals)
{
if(intervals.empty()) return vector<Interval> {};
sort(intervals.begin(),intervals.end(),cmp);
vector<Interval> res;
res.push_back(intervals[]);
for(int i = ; i < intervals.size(); i ++)
{
if(intervals[i].start > res.back().end)
res.push_back(intervals[i]);
else
res.back().end = max(res.back().end, intervals[i].end);
}
return res;
}
};

[LeetCode] 56. Merge Intervals(vector sort)的更多相关文章

  1. LeetCode 56. Merge Intervals (合并区间)

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  2. LeetCode: 56. Merge Intervals(Medium)

    1. 原题链接 https://leetcode.com/problems/merge-intervals/description/ 2. 题目要求 给定一个Interval对象集合,然后对重叠的区域 ...

  3. leetcode 56. Merge Intervals 、57. Insert Interval

    56. Merge Intervals是一个无序的,需要将整体合并:57. Insert Interval是一个本身有序的且已经合并好的,需要将新的插入进这个已经合并好的然后合并成新的. 56. Me ...

  4. 【leetcode】Merge Intervals(hard)

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  5. [LeetCode] 56 - Merge Intervals 合并区间

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  6. 34.Merge Intervals(合并序列)

    Level:   Medium 题目描述: Given a collection of intervals, merge all overlapping intervals. Example 1: I ...

  7. LeetCode OJ:Merge Intervals(合并区间)

    Given a collection of intervals, merge all overlapping intervals. For example,Given  [1,3],[2,6],[8, ...

  8. Leetcode#56 Merge Intervals

    原题地址 排序+合并,没啥好说的 第一次尝试C++的lambda表达式,有种写js的感觉,很神奇 c11就支持了lambda表达式,仔细想想,我学C++大概就是在09~10年,c11还没有发布,不得不 ...

  9. [LeetCode] 56. Merge Intervals 解题思路

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

随机推荐

  1. POJ 1113--Wall(计算凸包)

    Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 40363 Accepted: 13754 Description On ...

  2. Mysql8.0 3306端口无法远程连接

    在阿里云上搭建MySql8.0数据库服务,在阿里云上可以成功连接登陆使用,但用自己的电脑远程连接时却无法成功连接 经过资料查找,找出原因如下: 1.首先通过查看MySQL的的用户信息 可以看到host ...

  3. 【MYSQL笔记3】MYSQL过程式数据库对象之存储过程的调用、删除和修改

    mysql从5.0版本开始支持存储过程.存储函数.触发器和事件功能的实现. 我们以一本书中的例题为例:创建xscj数据库的存储过程,判断两个输入的参数哪个更大.并调用该存储过程. (1)调用 首先,创 ...

  4. CP-ABE ToolKit 安装笔记

    博主论文狗,好久没有来贴博客,最近做实验需要用到属性加密,了解了下CP-ABE,前来记录一下: 网上相关的博文较多,博主看了大部分的,认为下面这两个看完了基本就可以成功安装. 可参见博文: http: ...

  5. linux总结及常用命令

    一.操作系统的作用: 1.是现代计算机系统中最基本和最重要的系统软件  2.承上启下的作用  3.向下对硬件操作进行封装  4.向上对用户和应用程序提供方便访问硬件的接口 二.不同领域的操作系统: 1 ...

  6. visual studio 2015密钥

    Visual Studio Professional 2015简体中文版(专业版)KEY:HMGNV-WCYXV-X7G9W-YCX63-B98R2Visual Studio Enterprise 2 ...

  7. Windows 10 登录界面的背景图片地址

    C:\Users\******\appdata\Local\Packages\Microsoft.Windows.ContentDeliveryManager_********\LocalState\ ...

  8. 第一个python代码

    # -*- coding:utf-8 -*- user = raw_input("请输入用户名") passwd = raw_input("请输入密码") if ...

  9. 007---logging日志模块

    logging模块 用途:服务器运行日志.运维日志... import logging from logging.handlers import RotatingFileHandler, TimedR ...

  10. 杭电 1003 Max Sum (动态规划)

    参考:https://www.cnblogs.com/yexiaozi/p/5749338.html #include <iostream> #include <cstdio> ...