【LeetCode】252. Meeting Rooms 解题报告(C++)
- 作者: 负雪明烛
- id: fuxuemingzhu
- 个人博客:http://fuxuemingzhu.cn/
题目地址: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:
Input: [[0,30],[5,10],[15,20]]
Output: false
Example 2:
Input: [[7,10],[2,4]]
Output: true
题目大意
给定一个会议时间安排的数组,每个会议时间都会包括开始和结束的时间 [[s1,e1],[s2,e2],…] (si < ei),请你判断一个人是否能够参加这里面的全部会议。
解题方法
排序
很经典的题目,按照会议结束的时间进行排序。排序之后,遍历数组,判断当前会议结束的时间是否比下一个会议开始时间晚,如果是,那肯定就无法参加所有的会议了。
class Solution {
public:
bool canAttendMeetings(vector<vector<int>>& intervals) {
if (intervals.size() <= 1) return true;
sort(intervals.begin(), intervals.end(),
[](vector<int>& a, vector<int>&b) {return a[1] < b[1];});
for (int i = 0; i < intervals.size() - 1; i++) {
if (intervals[i][1] > intervals[i + 1][0])
return false;
}
return true;
}
};
日期
2019 年 9 月 17 日 —— 听了hulu宣讲会,觉得hulu的压力不大
【LeetCode】252. Meeting Rooms 解题报告(C++)的更多相关文章
- [LeetCode] 252. Meeting Rooms 会议室
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- LeetCode 252. Meeting Rooms (会议室)$
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode#252] Meeting Rooms
Problem: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2] ...
- [leetcode]252. Meeting Rooms会议室有冲突吗
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode] 253. Meeting Rooms II 会议室 II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
- 【LeetCode】Permutations II 解题报告
[题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...
- 【LeetCode】Island Perimeter 解题报告
[LeetCode]Island Perimeter 解题报告 [LeetCode] https://leetcode.com/problems/island-perimeter/ Total Acc ...
- 【LeetCode】01 Matrix 解题报告
[LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/descripti ...
随机推荐
- 【机器学*与R语言】2-懒惰学*K*邻(kNN)
目录 1.理解使用KNN进行分类 KNN特点 KNN步骤 1)计算距离 2)选择合适的K 3)数据准备 2.用KNN诊断乳腺癌 1)收集数据 2)探索和准备数据 3)训练模型 4)评估模型的性能 5) ...
- 通过mac地址确认二层交换机某个端口下接的终端设备IP
正常来说,二层交换机主要是通过mac地址进行通信的,这就导致我们无法直接通过arp表来确认交换机端口下终端设备的IP: 但我们仍然能通过查找二层交换机端口下学习到的mac地址,然后通过对照三层核心交换 ...
- Spark(九)【RDD的分区和自定义Partitioner】
目录 spark的分区 一. Hash分区 二. Ranger分区 三. 自定义Partitioner 案例 spark的分区 Spark目前支持Hash分区和Range分区,用户也可以自定义分区 ...
- 内存管理——new delete expression
C++申请释放内存的方法与详情表 调用情况 1.new expression new表达式在申请内存过程中都发生了什么? 编译器将new这个分解为下面的主要3步代码,①首先调用operator new ...
- D3-更改x轴的标签
记录,上代码
- 【Linux】【Services】【SaaS】Spinnaker
1. 简介 1.1. 说明: Spinnaker 是 Netflix 的开源项目,是一个持续交付平台,它定位于将产品快速且持续的部署到多种云平台上.Spinnaker 通过将发布和各个云平台解耦,来将 ...
- Java Maven项目搭建
创建空项目 New Project --> Empty Project --> ... 配置JDK Project Settings --> Project 选择JDK Module ...
- 【Java多线程】ExecutorService和ThreadPoolExecutor
ExecutorService Java.util.concurrent.ExecutorService接口代表一种异步执行机制,它能够在后台执行任务.因此ExecutorService与thread ...
- jQuery节点更新
一.插入子节点 var $newNode1 = $("<p>我是p标签</p>"); 加入之后,原来的会删除. 二.插入兄弟节点 三.替换节点 1.HTML ...
- 【Python】matplotlib直方图纵轴显示百分比
其实很简单,就是算了一下百分比权重,乘以了一个权重值 import matplotlib.pyplot as plt from matplotlib.ticker import FuncFormatt ...