题目地址:https://leetcode-cn.com/problems/meeting-rooms/

题目描述

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.

Example 1:

  1. Input: [[0,30],[5,10],[15,20]]
  2. Output: false

Example 2:

  1. Input: [[7,10],[2,4]]
  2. Output: true

题目大意

给定一个会议时间安排的数组,每个会议时间都会包括开始和结束的时间 [[s1,e1],[s2,e2],…] (si < ei),请你判断一个人是否能够参加这里面的全部会议。

解题方法

排序

很经典的题目,按照会议结束的时间进行排序。排序之后,遍历数组,判断当前会议结束的时间是否比下一个会议开始时间,如果是,那肯定就无法参加所有的会议了。

  1. class Solution {
  2. public:
  3. bool canAttendMeetings(vector<vector<int>>& intervals) {
  4. if (intervals.size() <= 1) return true;
  5. sort(intervals.begin(), intervals.end(),
  6. [](vector<int>& a, vector<int>&b) {return a[1] < b[1];});
  7. for (int i = 0; i < intervals.size() - 1; i++) {
  8. if (intervals[i][1] > intervals[i + 1][0])
  9. return false;
  10. }
  11. return true;
  12. }
  13. };

日期

2019 年 9 月 17 日 —— 听了hulu宣讲会,觉得hulu的压力不大

【LeetCode】252. Meeting Rooms 解题报告(C++)的更多相关文章

  1. [LeetCode] 252. Meeting Rooms 会议室

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  2. LeetCode 252. Meeting Rooms (会议室)$

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  3. [LeetCode#252] Meeting Rooms

    Problem: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2] ...

  4. [leetcode]252. Meeting Rooms会议室有冲突吗

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  5. [LeetCode] 253. Meeting Rooms II 会议室 II

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  6. LeetCode 1 Two Sum 解题报告

    LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...

  7. 【LeetCode】Permutations II 解题报告

    [题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...

  8. 【LeetCode】Island Perimeter 解题报告

    [LeetCode]Island Perimeter 解题报告 [LeetCode] https://leetcode.com/problems/island-perimeter/ Total Acc ...

  9. 【LeetCode】01 Matrix 解题报告

    [LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/descripti ...

随机推荐

  1. perl substr

    substr EXPR,OFFSET,LENGTH,REPLACEMENT substr EXPR,OFFSET,LENGTH substr EXPR,OFFSET Extracts a substr ...

  2. 毕业设计之LNP+DISCUZ +分离的数据库操作

    环境介绍: CentOS6.9最小化安装 https://nginx.org/download/nginx-1.16.1.tar.gz https://www.php.net/distribution ...

  3. zabbix忘记密码——进入数据库修改

    登录数据库,选择zabbix数据库 查看数据库里面的表 用户和用户密码在users表里面 将你想设置的密码进行MD5加密处理: 更新密码即可: update users set passwd=&quo ...

  4. C语言 自定义函数按行读入文件

    在之前的博客中 https://www.cnblogs.com/mmtinfo/p/13036039.html 读取一行的getline()函数是GNU 的扩展函数. 这里用自定义函数实现这个功能,从 ...

  5. 计算机网络-4-7-内部网关协议OSPF

    内部网关协议OSPF(开放最短路径优先) 出现的原因:为了克服RIP协议的缺点在1989年开发出来,**开放 表明OSPF协议不受任何厂家的限制.最短路径优先是因为使用了最短路径算法SPF**. OS ...

  6. 普通用户iptables规则持久化,开机自动恢复

    本文档对于docker环境下并不适用,docker环境的iptables持久化请参考https://www.cnblogs.com/wiseo/p/15000745.html 添加iptables规则 ...

  7. 4.2 rust 命令行参数

     从命令行读取参数 use std::env; fn main() { let args: Vec<String> = env::args().collect(); println!(&q ...

  8. Linux学习 - 权限管理命令

    一.chmod(change the permissions mode of a file) 1 功能 改变文件或目录权限 root 与 所有者 可进行此操作 2 语法 chmod  [(ugoa) ...

  9. navigationItem的leftBarButtonItem和rightBarButtonItem隐藏

    - (void)showEdit { if (不符合显示条件) { self.navigationItem.rightBarButtonItem.customView.hidden = YES; // ...

  10. APICloud - 提交项目 点击右键 没有git这个选项

    你们是不是也遇到过这个问题,吧项目检出来后,花了很久的时间,好不容易吧项目改完,提交的时候点击鼠标右键,发现git选项没有在里面了,找不到,但是这个问题也不是很常遇到,机率很小,下面我来告诉你们吧 原 ...