当前位置:网站首页>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_ Dmfldr tool instructions
- Positional argument after keyword argument
- Kernel pwn 基础教程之 Heap Overflow
- Xshell remote access tool
- Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]
- 剑指offer JZ10斐波那契数列
- LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)
- Hololens 2 development 101: create the first hololens 2 Application
- Dameng database_ Common commands
- Simple but easy to use: using keras 2 to realize multi-dimensional time series prediction based on LSTM
猜你喜欢

Simple three-step fast intranet penetration

快速简单搭建FTP服务器,并内网穿透实现公网访问【无需公网IP】

UE4: what is the gameplay framework

Xshell remote access tool

Basic knowledge of unity and the use of some basic APIs

【217】#!/usr/bin/env 的意义

UE4:浅谈什么是GamePlay框架

First knowledge of graphics

ue4 瞄准偏移
![Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]](/img/2a/43ba2839b842e0901a550d2883b883.png)
Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]
随机推荐
Machine learning & deep learning introduction information sharing summary
Hololens 2 Chinese development document MRTK V2
Lua基础
MySQL从基础到入门到高可用
Unity (II) more APIs and physical engines
Openpose2d转换3d姿态识别
LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)
Find the ArrayList < double > with the most occurrences in ArrayList < ArrayList < double >
Basic knowledge of unity and the use of some basic APIs
ue4 换装系统 2.换装系统的场景捕捉
Dameng database_ Logical architecture foundation
【251】常见的测试工具
Oserror: [winerror 127] the specified program cannot be found. Error loading “caffe2_detectron_ops.dll“ or one of its dependencies
10大漏洞评估和渗透测试工具
【219】app 测试和web测试的区别点?
The public network uses Microsoft Remote Desktop remote desktop to work remotely at any time
异地远程连接在家里的群晖NAS【无公网IP,免费内网穿透】
Hololens2 development: use MRTK and simulate eye tracking
IP notes (8)
Dameng database_ Common initialization parameters