leetcode 729. My Calendar I(日程1)

C# 开发 WPS 插件实战:从环境搭建到功能实现(附完整代码) 本文提供了一份详尽的C#开发WPS插件实战指南,涵盖从环境搭建到功能实现的完整流程。通过COM技术,开发者可以创建自定义插件,为WPS Office扩展自动化功能,如文档处理与格式转换。文章包含核心概念解析、Ribbon界面集成、调试部署方法及完整代码示例,帮助开发者快速上手。 阅读详情

You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a double booking.

A double booking happens when two events have some non-empty intersection (i.e., some moment is common to both events.).

The event can be represented as a pair of integers start and end that represents a booking on the half-open interval [start, end), the range of real numbers x such that start <= x < end.

Implement the MyCalendar class:

MyCalendar() Initializes the calendar object.
boolean book(int start, int end) Returns true if the event can be added to the calendar successfully without causing a double booking. Otherwise, return false and do not add the event to the calendar.

Example 1:

Input
[“MyCalendar”, “book”, “book”, “book”]
[[], [10, 20], [15, 25], [20, 30]]
Output
[null, true, false, true]

Explanation
MyCalendar myCalendar = new MyCalendar();
myCalendar.book(10, 20); // return True
myCalendar.book(15, 25); // return False, It can not be booked because time 15 is already booked by another event.
myCalendar.book(20, 30); // return True, The event can be booked, as the first event takes every time less than 20, but not including 20.

每段[start, end)表示日程是从start~end(不包含end), 日程不能有重叠的部分,
如果能加入日程,返回true, 否则false.

思路:

主要是判断每一段是否与已有的日程有重叠,
新进来的日程可以跟已有的每一段比较,
两段日程(s1, e1), (s2, e2)有重叠表示要么s2在s1 ~ e1之间,要么e2在s1 ~ e1之间。
没有重叠的话把新的日程加进去,返回true。

class MyCalendar {
    List<Pair<Integer, Integer>> calendar;
    public MyCalendar() {
        calendar = new ArrayList<>();
    }
    
    public boolean book(int start, int end) {
        for(Pair<Integer, Integer> tmp : calendar) {
            if(end > tmp.getKey() && start < tmp.getValue()) {
                return false;
            }           
        }
        calendar.add(new Pair(start, end));
        return true;
    }
}

还有一种beat 99%的方法,
构造一个类似双向链表的数据结构,每个节点是一个日程(start, end)
当没有重叠时:即s1 >= e1 或者 e2 <= s1时
要插入新的节点,通过移动链表的指针进行插入操作。

如果有重叠,直接返回false。

class MyCalendar {
    private class CalendarNode{
        int start;
        int end;
        CalendarNode next;
        CalendarNode prev;
        
        public CalendarNode(int start, int end){
            this.start = start;
            this.end = end;
        }
    }
    
    CalendarNode calendar;
    public MyCalendar() {
        calendar = null;
    }
    
    public boolean book(int start, int end) {
        if (calendar == null) {
            calendar = new CalendarNode(start, end);
            return true;
        } else {
            return insertNewCalendarNode(start, end);
        }
    }
    
    private boolean insertNewCalendarNode(int start, int end){
        CalendarNode cn = calendar;
        
        //没有重叠的情况
        while (end <= cn.start || start >= cn.end) {
            if (cn.start >= end) {
                if (cn.prev != null) {
                    cn = cn.prev;
                } else {
                    cn.prev = new CalendarNode(start, end);
                    return true;
                }
            } else if (cn.end <= start) {
                if (cn.next != null) {
                    cn = cn.next;
                } else {
                    cn.next = new CalendarNode(start, end);
                    return true;
                }
            }
        }
        
        return false;
    }
}
基于TENG的呼吸测量与识别系统:从蓝牙到WiFi的改造与上位机实现 本文介绍了一种基于摩擦纳米发电机(TENG)的呼吸测量系统改造方案,将原有蓝牙通信升级为WiFi传输。系统通过TENG传感器采集呼吸信号,STM32微控制器处理数据后,经ESP8266 WiFi模块发送至上位机。文中详细阐述了硬件改造(四通道改单通道、蓝牙换WiFi)、嵌入式软件修改(包括ESP8266驱动、数据采集与TCP通信实现)以及上位机软件设计。改造后的系统提升了传输距离和稳定性,为可穿戴健康监测提供了更优解决方案。 阅读详情

相关推荐

9.Vue前端使用iframe集成帆软报表的单点登录

CPT普通报表的地址:【帆软的服务http】+【/webroot/decision/view/report?【帆软的服务http】+【/webroot/decision/view/form?// fineReportHttp:帆软部署的地址。//如果为ie浏览器则页面加载完成后立即执行。// fineLinkSrc:帆软报表的url。//其他浏览器则重新加载onload事件。// 拿到配置的帆软报表的地址参数。//判断是否为ie浏览器。// 帆软报表登录和打开。// 帆软报表登录和打开。

qq_27860623的博客 4647

729. 我的日程安排表 I

实现一个MyCalendar类来存放你的日程安排。如果要添加的时间内没有其他安排,则可以存储这个新的日程安排。 MyCalendar有一个book(int start, int end)方法。它意味着在 start 到 end 时间内增加一个日程安排,注意,这里的时间是半开区间,即[start, end), 实数x的范围为, start <= x < end。 当两...

start_lie的博客 359

将3DMax编辑的动画,导入给已经绑定蒙皮好的模型给Unity使用

现在程序猿想做独立游戏,即容易,也难。 说容易,引擎越来越傻瓜化。 说难,到哪去找靠谱的美术? 好在伟大的AssetStore(还有淘宝上)有大批不赖的资源可以用。 现成的模型,是好,但是,没有配套的动作,却是一件让人头疼的事情,即使用IK动画,也不能完美的弥补这一缺陷。 虽然Unity具备 retargeting 功能,但是,也不是万能的,很多情况下,非标准的骨骼会导致

正经的时候都在打游戏 1万+

【LeetCode】729. My Calendar I 解题报告

【LeetCode】729. My Calendar I 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/my-calendar-i/description/ 题目描述: Implement a MyCalendar class to store your events. A new event can be a...

负雪明烛 1417

RunHarmony报错解析:如何解决data.use与cell.embeddings维度不匹配问题

本文深入解析了单细胞数据分析中RunHarmony函数报错'non-conformable arguments'的根源,即data.use与cell.embeddings矩阵维度不匹配。核心原因是assay(如RNA与integrated)错配导致细胞ID或数量不一致。文章提供了三种解决方案:最推荐显式指定assay.use参数,也可设置project.dim=FALSE或统一数据环境,并给出了最佳实践指南以避免此类错误。

weixin_29093017的博客 575

chipseeker Y叔

这一次讲解非常重要的peak注释,注释在ChIPseeker里只需要用到一个函数annotatePeak,它可以满足大家各方面的需求。 输入 当然需要我们上次讲到的BED文件,ChIPseeker自带了5个BED文件,用getSampleFiles()可以拿到文件的全路径,它返回的是个named list,我这里取第4个文件来演示。annotatePeak的输入也可以是GRanges对象,你如果用R做peak calling的话,直接就可以衔接上ChIPseeker了。 require(ChIPseeke

生信小博士的博客 1588

[leetcode]729. My Calendar I

[leetcode]729. My Calendar I Analysis waiting~—— [每天刷题并不难0.0] Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking. Your ...

weixin_32135877的博客 277

专栏丨华为HN8145XR光猫获取超级管理员密码

摘要:本文详细介绍了华为HN8145xr光猫获取超级管理员权限的完整步骤。首先通过ONT使能工具补全shell,然后利用Telnet登录光猫后台进行操作。文章提供了多种获取超级密码的方法,包括配置文件解密、一键查询工具等,并针对联通光猫特别说明了默认密码格式(CUAdmin+后八位数字)。此外,还介绍了恢复出厂设置、修改SSID等实用操作,帮助用户完全掌控光猫设备。文末附有详细的命令行操作指南,适合有一定技术基础的用户参考。

8241

LeetCode //C - 729. My Calendar I

This article introduces a C language implementation for managing calendar events. The main function is to add new events and ensure that double bookings with overlapping times do not occur. The core of the implementation is to use a linked list to store al

Made in Code 1064

在Ubuntu 22.04上从零搭建FVCOM环境:手把手搞定Linux、Intel编译器与NetCDF库

本文详细指导在Ubuntu 22.04上从零搭建FVCOM环境,涵盖Linux系统配置、Intel编译器安装、NetCDF库编译及常见问题解决。通过手把手教程,帮助科研人员高效完成水动力数值模拟环境的部署,特别适合水环境研究领域的初学者。

weixin_30613727的博客 650

环境配置与基础教程:2026大厂标准:使用 DVC (Data Version Control) 实现 YOLO 数据集版本控制全链路管理

本文介绍了使用DVC 3.0对YOLO数据集进行全链路版本控制的方法。主要内容包括: DVC 3.0的核心增强:内容块级缓存去重、并行云传输、AI智能体元数据跟踪等新特性,可显著提升YOLO数据集管理效率。 环境配置:详细说明DVC 3.0的安装步骤、项目初始化方法以及远程存储配置方案(支持S3、GCS、Azure等多种存储后端)。 目录结构规范:提供符合大厂MLOps标准的项目目录结构设计。 实战操作: 原始数据版本化 多格式标注数据版本控制 版本切换方法 优势说明:DVC通过哈希指针机制管理大型数据集,

ZXSXJ的博客 147

【Leetcode】729. My Calendar I

题目地址: https://leetcode.com/problems/my-calendar-i/ 实现一个类,可以做如下操作:给定一个区间[a,b][a,b][a,b],如果之前存储的区间里和这个区间没有相交的(端点重合不算),就将其插入返回true,否则不插入返回false。 可以用java里的TreeMap来做,key为区间左端点,value为对应的右端点。在插入时,先将左右两边左端点最靠近aaa的区间找出来(可以用TreeMap的floorKey和ceilingKey方法来做),左边区间与[a,b

数学、算法爱好者的博客 325

大模型的应用与微调:如何调用 LLM?从 OpenAI API 到本地部署

本篇文章介绍了如何调用 OpenAI、DeepSeek、Manus、通义千问等大模型 API,并探讨了 LLM 本地部署的方法。在实际应用中,可以根据需求选择云端 API 或本地化部署方案,以满足不同的计算需求和隐私要求。下一篇:大模型微调与 RAG 技术(LoRA、QLoRA、向量数据库)

晴天彩虹雨的博客 1156

729. My Calendar I

763. Partition Labels 开篇闲话: leetcode间隔一个星期未刷了,满满的罪恶感。因为10个高中同学元旦来我的城市找我玩,带他们在外面浪了四天,然后回学校补图形学作业、形势与政策论文、实训报告,这就又过了几天。其实这几天是可以刷题的,只是感觉自己颓废了很多,那种对什么都提不起兴趣的感觉(自从上星期实习辞职后,生活突然变得空虚),,,昨天看到cvte的补招笔试过了,竟然过了,...

凌凌小博客 295

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

[Swift]LeetCode729. 我的日程安排表 I | My Calendar I

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)➤GitHub地址:https://github.com/strengthen/LeetCode➤原文地址:https://www.cnblogs.com/stren...

weixin_30699741的博客 197

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

[leetcode] 729. My Calendar I @ python

原题 Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking. Your class will have the method, book(int start, int end). Formally,...

闲庭信步 790

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

leetcode[729] My Calendar I

问题:实现一个 MyCalendar 类来存放你的日程安排。如果要添加的时间内没有其他安排,则可以存储这个新的日程安排。 思路: 暴力解法:每次插入与已预定安排逐一进行比较,时间复杂度为O(n^2)。 平衡树法:借用C++中的map,时间复杂度为O(nlogn)。 class MyCalendar { public: MyCalendar() { } ...

Black Mamba的博客 232

leetcode 729. My Calendar I 我的日程安排表 I

看官方题解的话,也可以用有序集合,然后二分查找 官方题解的:

邹九的个人博客 177

[LeetCode 729] My Calendar I

Implement aMyCalendarclass to store your events. A new event can be added if adding the event will not cause a double booking. Your class will have the method,book(int start, int end). Formally, t...

ExcitedZhang的博客 329

LeetCode | 729. My Calendar I

Implement a MyCalendar classto store your events. A new event can be added if adding the event will notcause a double booking. Your class will have the method, book(intstart, int end).Formally, thi

u012737193的博客 248

leetcode 729, 731, 732. My Calendar I, II, III | 729. 我的日程安排表 I, II, III(线段树)

题目 https://leetcode.com/problems/my-calendar-i/ 题解 看了左神课之后,自己实现了下改造后的线段树(非常不优雅),因为数组放不下,所以自建 Node 结构。 class Node { int l; int r; boolean used; // 当前范围已全覆盖 Node left; Node right; public Node(int l, int r) { this.l = l;

寒泉 4万+

LEETCODE: 729. My Calendar I & 731. My Calendar II

729. My Calendar IImplement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.Your class will have the method, book(int start, int en

博客已退休 1058

LeetCode 729/731. My Calendar I + II

My Calendar I hash table + binary search,注意边界情况即可。 class MyCalendar { private: map<int,int> m; // map[start] -> end public: MyCalendar() {} bool book(int star...

weixin_34110749的博客 183

leetcode-每日一题729. 我的日程安排表 I

leetcode-每日一题729. 我的日程安排表 I

林钟一的博客 324

LeetCode 729. My Calendar I【设计;有序集合,二分查找;线段树】中等

本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还建立了相关的。

memcpy0的博客 582

LeetCode 729 My Calendar I

Problem description: Implement aMyCalendarclass to store your events. A new event can be added if adding the event will not cause a double booking. Your class will have the method,book(int st...

dianguju2418的博客 138
上一篇: leetcode 378. Kth Smallest Element in a Sorted Matrix(排好序的矩阵中第K小的元素)
下一篇: leetcode 823. Binary Trees With Factors(因子二叉树)
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值