当前位置:网站首页>力扣986.区间列表的交集
力扣986.区间列表的交集
2022-07-24 05:23:00 【u_guess_】
力扣986.区间列表的交集(自己复习所用)
考虑最小末端点,例如示例1中,最小末端点在A[0],那么因为两个列表中区间都不相交的缘故,A[0]只可能与B中的一个区间B[0]相交(否则B中区间会相交),那么A[0]在后续不可能与其他区间相交,则可以不再考虑(删去),此时就需要寻找下一个最小末端点,来继续上诉步骤。
为什么下一个最小末端点不是B[0]呢,因为可能存在下面这种情况:
因此代码如下:
class Solution:
def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:
ret=[]
i=j=0 #双指针指向当前比较区间
while i<len(firstList) and j<len(secondList):
#找相交区间
start=max(firstList[i][0],secondList[j][0])
end=min(firstList[i][1],secondList[j][1])
if start<=end:
ret.append([start,end])
#找最小末端点存在的区间
if firstList[i][1]<secondList[j][1]:
i+=1
else:
j+=1
return ret
边栏推荐
- Remote connection to Qunhui NAS at home [no public IP, free intranet penetration]
- Use intranet penetration to realize public network access to the Intranet
- 初识图形学
- Using keras and LSTM to realize time series prediction of long-term trend memory -lstnet
- 【219】app 测试和web测试的区别点?
- IP notes (11)
- 使用Keras和LSTM实现对于长期趋势记忆的时间序列预测-LSTNet
- leetcode剑指offer JZ73 翻转单词序列
- Lua Foundation
- Force buckle: 1-sum of two numbers
猜你喜欢

How does the latest version of text (TMP) UI text of unity display in Chinese

IP课笔记(4)

【301】怪诞行为学-可预测的非理性

公网访问内网IIS网站服务器【无需公网IP】

IP课(OSPF)综合实验

LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)

IP课总结(3)

Do not rent servers, build your own personal business website (1)

IA课总结(2)

IP job (2) rip
随机推荐
Hololens2 development: use MRTK and simulate eye tracking
leetcode 不用加减乘除算加法 || 二进制中1的个数
Simple but easy to use: using keras 2 to realize multi-dimensional time series prediction based on LSTM
Simple three-step fast intranet penetration
如何建立一个仪式感点满的网站,并发布到公网 1-2
使用Keras实现CNN+BiLSTM+Attention的多维(多变量)时间序列预测
Do not rent servers, build your own personal business website (1)
什么是单调栈
【214】什么是自动化框架
本地搭建WordPress个人博客,并内网穿透发布上线 (22)
【217】#!/usr/bin/env 的意义
【218】CS架构和BS架构以及数据放在服务端和客户端的利与弊?
IP class notes (4)
常用工作方法总结(7S、SWOT分析、PDCA循环、SMART原则、6W2H、时间管理、WBS、二八原则)
Calculation steps of principal component analysis
unity最新版本的Text(TMP)UI文本怎么显示中文
【219】app 测试和web测试的区别点?
【301】怪诞行为学-可预测的非理性
Unity (III) three dimensional mathematics and coordinate system
leetcode剑指offer JZ42 连续子数组的最大和