当前位置:网站首页>Li Kou 986. Intersection of interval lists
Li Kou 986. Intersection of interval lists
2022-07-24 06:19:00 【u_ guess_】
Power button 986. Intersection of interval list ( Review by yourself )
Consider the minimum end point , For example 1 in , The minimum end point is A[0], So because the intervals in the two lists do not intersect ,A[0] Only possible with B An interval in B[0] The intersection ( otherwise B The central district will intersect ), that A[0] It is impossible to intersect with other intervals in the future , You can no longer consider ( delete ), At this point, we need to find the next minimum end point , To continue the appeal process .
Why is the next minimum end point not B[0] Well , Because there may be the following :
So the code is as follows :
class Solution:
def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:
ret=[]
i=j=0 # The double pointer points to the current comparison interval
while i<len(firstList) and j<len(secondList):
# Find intersection interval
start=max(firstList[i][0],secondList[j][0])
end=min(firstList[i][1],secondList[j][1])
if start<=end:
ret.append([start,end])
# Find the interval where the minimum end point exists
if firstList[i][1]<secondList[j][1]:
i+=1
else:
j+=1
return ret
边栏推荐
- Dameng database_ Trigger, view, materialized view, sequence, synonym, auto increment, external link and other basic operations
- IP notes (9)
- Getting started with Lunix commands - user and file permissions (Chmod details)
- MySQL数据库—SQL汇总(记得关注我!中国加油!)
- 不租服务器,自建个人商业网站(如何购买域名)
- UE4 replacement system 3. Final results
- 【222】内存溢出及定位
- 一批面试题及答案_20180403最新整理
- [no need for public IP] configure a fixed public TCP port address for remote desktop raspberry pie
- 【226】wireshark的参数使用说明
猜你喜欢
随机推荐
Find the ArrayList < double > with the most occurrences in ArrayList < ArrayList < double >
Unity (II) more APIs and physical engines
NTP error: no server suitable for synchronization found
LSTM neural network
Set up a WordPress personal blog locally and launch it through the intranet (22)
Public access intranet IIS website server [no public IP required]
Do not rent a server, build your own personal business website (how to buy a domain name)
Dameng database_ User password policy
公网使用Microsoft Remote Desktop远程桌面,随时远程办公
Dameng database_ Summary of supported data types
Openpose unity plug-in deployment tutorial
Lua Foundation
leetcode剑指offer JZ23:链表中环的入口节点
Unity2d horizontal game jump real-time response
一批面试题及答案_20180403最新整理
Dameng database_ Logical architecture foundation
Openpose2d transform 3D pose recognition
【226】wireshark的参数使用说明
配置固定的远程桌面地址【内网穿透、无需公网IP】
Basic knowledge of unity and the use of some basic APIs









