My Calendar III
class MyCalendarThree(object):
"""
Implement a MyCalendarThree class to store your events. A new event can always be added.
Your class will have one method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end.
A K-booking happens when K events have some non-empty intersection (ie., there is some time that is common to all K events.)
For each call to the method MyCalendar.book, return an integer K representing the largest integer such that there exists a K-booking in the calendar.
Your class will be called like this: MyCalendarThree cal = new MyCalendarThree(); MyCalendarThree.book(start, end)
""" def __init__(self):
import collections
self.delta = collections.Counter() def book(self, start, end):
"""
注意 这种方式 求的是里面重复的最大的次数,而不是最后一次加入的日历和前面重复的最大次数,
:param start:
:param end:
:return:
:param start:
:param end:
:return:
"""
self.delta[start] += 1
self.delta[end] -= 1 active = ans = 0
for x in sorted(self.delta):
if x > end:
break
active += self.delta[x]
if active > ans:
ans = active
print(active,ans)
print("-------")
return ans s = MyCalendarThree()
r1 = s.book(1, 3)
r2 = s.book(2, 4)
r3 = s.book(5, 6)
# r4 = s.book(2, 7)
# r5 = s.book(5, 10)
# print(r1, r2, r3,r4,r5)
print(r3)
My Calendar III的更多相关文章
- 【LeetCode】732. My Calendar III解题报告
[LeetCode]732. My Calendar III解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/my-calendar ...
- [LeetCode] 729. My Calendar I 731. My Calendar II 732. My Calendar III 题解
题目描述 MyCalendar主要实现一个功能就是插入指定起始结束时间的事件,对于重合的次数有要求. MyCalendar I要求任意两个事件不能有重叠的部分,如果插入这个事件会导致重合,则插入失败, ...
- [LeetCode] My Calendar III 我的日历之三
Implement a MyCalendarThree class to store your events. A new event can always be added. Your class ...
- [Swift]LeetCode732. 我的日程安排表 III | My Calendar III
Implement a MyCalendarThree class to store your events. A new event can always be added. Your class ...
- Segment Tree-732. My Calendar III
Implement a MyCalendarThree class to store your events. A new event can always be added. Your class ...
- 732. My Calendar III (prev)
Implement a MyCalendarThree class to store your events. A new event can always be added. Your class ...
- LeetCode 732. My Calendar III
原题链接在这里:https://leetcode.com/problems/my-calendar-iii/ 题目: Implement a MyCalendarThree class to stor ...
- LeetCode My Calendar I
原题链接在这里:https://leetcode.com/problems/my-calendar-i/description/ 题目: Implement a MyCalendar class to ...
- LeetCode 731. My Calendar II
原题链接在这里:https://leetcode.com/problems/my-calendar-ii/ 题目: Implement a MyCalendarTwo class to store y ...
随机推荐
- sqlmap完成简单的sql注入
扫描目标站点,是否存在注入 --users获取用户名 --dump --tables探测表和数据库信息 跑出来的字段 admin --dump -T admin -C admin,password暴库 ...
- Codeforces 839A Arya and Bran【暴力】
A. Arya and Bran time limit per test:1 second memory limit per test:256 megabytes input:standard inp ...
- BZOJ2282: [Sdoi2011]消防
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2282 答案一定是在直径上的一段,然后答案一定不会小于不在直径上的点到直径的距离(要是可以的话那 ...
- 最小生成树&最短路基础算法总结
[最短路问题] 解决最短路问题有以下算法:Dijkstra算法,Bellman-Ford算法,Floyd算法,和SPFA算法和启发式搜索算法A*; 每个算法都有它的特点可以解决某些特定的问题,例如:F ...
- 支付宝当面付开发(java)
支付宝当面付开发(java) 业务流程: 接入准备: 直接下载demo: https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7 ...
- spring自带定时器
http://www.cnblogs.com/pengmengnan/p/6714203.html 注解模式的spring定时器1 , 首先要配置我们的spring.xmlxmlns 多加下面的内容. ...
- 怎么从一台电脑的浏览器输入地址访问另一台电脑服务器(WAMP服务器已搭建,PHPSTORM装好了)
服务器电脑WAMP环境搭建好了,浏览器输入LOCALHOST就能访问本地 WAMP/WWW 目录下PHP文件,怎么样才能从另一台电脑通过浏览器访问呢?求详细步骤... glwbdtb | 浏览 180 ...
- J.U.C JMM. pipeline.指令重排序,happen-before(续MESI协议)
缓存(Cache) CPU的读/写(以及取指令)单元正常情况下甚至都不能直接访问内存——这是物理结构决定的:CPU都没有管脚直接连到内存.相反,CPU和一级缓存(L1 Cache)通讯,而 ...
- PostgreSql问题:ERROR: column "1" does not exist
摘录自:http://blog.csdn.net/shuaiwang/article/details/1807421 在PostgreSQL中,不论是在pgAdmin中还是在命令行控制台里面,在SQL ...
- WKWebView--JS调用OC的方法
WKWebView---JS调用OC方法 一.使用的协议进行简单的介绍 1.在WKWebView中OC和JS交互也非常简单,WebKit的库中有个代理WKScriptMessageHandler就是专 ...