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 ...
随机推荐
- HDU 2037 今年暑假不AC(贪心,区间更新,板子题)
今年暑假不AC Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- EMC题
[面试题]EMC易安信面试题解 1. 除以59的余数是多少. 来自wiki:费马小定理是数论中的一个定理:假如a是一个整数,p是一个質数,那么 如果a不是p的倍数,这个定理也可以写成 这个书写方式更加 ...
- 微信小程序 登录流程规范解读
一. 官方登录时序图 二. 简单理解 这里仅按照官方推荐的规范来 0. 前置条件 一共有三端: - 微信小程序客户端 - 第三方服务器端(自己搭建) - 微信服务器端 1. 客户端获得code,并将c ...
- Vuex初识
vuex是vue中单向数据流的一个状态管理模式,它可以集中存储管理应用中所有组件的状态,并且有一套相应的规则可以去预测数据的变化.类似与此的还有react中的redux,dva等状态管理模式. 一般我 ...
- 百度编辑器ueditor
,怎么将上传的图片路径改到项目的public/uploads文件夹呢?哪位大神改过
- LNMP状态管理命令
https://lnmp.org/faq/lnmp-status-manager.html LNMP状态管理命令: LNMP 1.2+状态管理: lnmp {start|stop|reload|res ...
- (实用篇)使用PHP生成PDF文档
http://mp.weixin.qq.com/s?__biz=MzIxMDA0OTcxNA==&mid=2654254929&idx=1&sn=8715d008d19af70 ...
- @RequestMapping 相关 spring
* * @param request HttpServletRequest * @param delList 削除Idエスト * @return 削除結果 * @th ...
- [转]【Java】内部类(Inner Class)如何创建(new)
简单来说,内部类(inner class)指那些类定义代码被置于其它类定义中的类:而对于一般的.类定义代码不嵌套在其它类定义中的类,称为顶层(top-level)类.对于一个内部类,包含其定义代码的类 ...
- Oracle问题之字符集问题,登陆sqlplus出现问号
退出sql SET NLS_LANG=AMERICAN_AMERICA.ZHS16GBK show parameter nls_la