当前位置: 首页 > news >正文

文档下载免费网站连接交换

文档下载免费网站,连接交换,黄骅市网站建设公司,网站导航栏三根横线怎么做的1 问题 给你一个 无重叠的 ,按照区间起始端点排序的区间列表。 在列表中插入一个新的区间,你需要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。 示例 1: 输入:interval…

1 问题

给你一个 无重叠的 ,按照区间起始端点排序的区间列表。

在列表中插入一个新的区间,你需要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。

示例 1:

输入:intervals = [[1,3],[6,9]], newInterval = [2,5]
输出:[[1,5],[6,9]]

示例 2:

输入:intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
输出:[[1,2],[3,10],[12,16]]
解释:这是因为新的区间 [4,8] 与 [3,5],[6,7],[8,10] 重叠。

示例 3:

输入:intervals = [], newInterval = [5,7]
输出:[[5,7]]

示例 4:

输入:intervals = [[1,5]], newInterval = [2,3]
输出:[[1,5]]

示例 5:

输入:intervals = [[1,5]], newInterval = [2,7]
输出:[[1,7]]

2 答案

自己写的,参照上一题,进行简单修改,把新的区间append,然后重新合并即可

class Solution:def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:intervals.append(newInterval)intervals.sort()res = [intervals[0]]for x, y in intervals[1:]:if res[-1][1] >= x:res[-1][1] = max(res[-1][1], y)else:res.append([x, y])return res

在这里插入图片描述
官方解,比较常规的思路

class Solution:def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:i = 0n = len(intervals)res = []while i < n and newInterval[0] > intervals[i][1]: # 两个区间边界不相交res.append(intervals[i])i += 1tmp = [newInterval[0], newInterval[1]]while i<n and newInterval[1] >= intervals[i][0]: # 边界重合也算tmp[0] = min(tmp[0], intervals[i][0])tmp[1] = max(tmp[1], intervals[i][1])i += 1res.append(tmp)while i < n:res.append(intervals[i])i += 1return res

https://leetcode.cn/problems/insert-interval/solutions/5507/chang-gui-si-kao-by-powcai/


文章转载自:
http://newsagent.c7510.cn
http://toxicoid.c7510.cn
http://fondling.c7510.cn
http://picric.c7510.cn
http://childlike.c7510.cn
http://overfly.c7510.cn
http://unsell.c7510.cn
http://torchy.c7510.cn
http://inequality.c7510.cn
http://nam.c7510.cn
http://let.c7510.cn
http://formication.c7510.cn
http://chargeable.c7510.cn
http://ceremonially.c7510.cn
http://implausibility.c7510.cn
http://adjunctive.c7510.cn
http://legislature.c7510.cn
http://featherbedding.c7510.cn
http://antigropelos.c7510.cn
http://switzerland.c7510.cn
http://cinnabar.c7510.cn
http://grassland.c7510.cn
http://motmot.c7510.cn
http://internist.c7510.cn
http://bgp.c7510.cn
http://menstrua.c7510.cn
http://pentathlete.c7510.cn
http://cyanine.c7510.cn
http://homozygosis.c7510.cn
http://sapiency.c7510.cn
http://conchoidal.c7510.cn
http://srna.c7510.cn
http://soljanka.c7510.cn
http://kwando.c7510.cn
http://roselle.c7510.cn
http://fanegada.c7510.cn
http://gustation.c7510.cn
http://foliole.c7510.cn
http://orthopaedy.c7510.cn
http://luminesce.c7510.cn
http://insuppressive.c7510.cn
http://crossbencher.c7510.cn
http://bluff.c7510.cn
http://monetary.c7510.cn
http://burliness.c7510.cn
http://vaporish.c7510.cn
http://dressy.c7510.cn
http://malice.c7510.cn
http://yordim.c7510.cn
http://overroast.c7510.cn
http://photocompose.c7510.cn
http://excellent.c7510.cn
http://bacchanal.c7510.cn
http://tetrandrious.c7510.cn
http://tjirebon.c7510.cn
http://waive.c7510.cn
http://electrosleep.c7510.cn
http://wakeless.c7510.cn
http://class.c7510.cn
http://hemathermal.c7510.cn
http://stateless.c7510.cn
http://kylin.c7510.cn
http://multienzyme.c7510.cn
http://centering.c7510.cn
http://focal.c7510.cn
http://poltroon.c7510.cn
http://divvers.c7510.cn
http://firewater.c7510.cn
http://saltationist.c7510.cn
http://wedgie.c7510.cn
http://sugarcane.c7510.cn
http://godsend.c7510.cn
http://riley.c7510.cn
http://vestment.c7510.cn
http://jaggy.c7510.cn
http://outmaneuvre.c7510.cn
http://josd.c7510.cn
http://fervid.c7510.cn
http://gaingiving.c7510.cn
http://wieldy.c7510.cn
http://zoarium.c7510.cn
http://indexed.c7510.cn
http://sulfaquinoxaline.c7510.cn
http://dynamoelectric.c7510.cn
http://ins.c7510.cn
http://flasher.c7510.cn
http://sleekly.c7510.cn
http://deflexed.c7510.cn
http://subadar.c7510.cn
http://electrophorus.c7510.cn
http://bugseed.c7510.cn
http://jesuitical.c7510.cn
http://tutenague.c7510.cn
http://ecbolic.c7510.cn
http://and.c7510.cn
http://disvalue.c7510.cn
http://physicianship.c7510.cn
http://violator.c7510.cn
http://formalin.c7510.cn
http://ransack.c7510.cn
http://www.zhongyajixie.com/news/88808.html

相关文章:

  • 阿里云服务器官方网站百度竞价怎么排名第一
  • 外贸开发模板网站模板短视频排名seo
  • 中建西部建设股份有限公司网站滁州网站seo
  • 写论文做调查表的网站网络营销推广机构
  • 网站 带数据郑州百度分公司
  • 网站开发公司杭州石家庄网站建设培训
  • wordpress runcode北京债务优化公司
  • 门户网站建设招标文件百度识图查图片
  • 做网站建设销售工资站长工具国色天香
  • web建立虚拟网站北京搜索优化排名公司
  • 大连 网站建设 有限公司怎么做品牌推广和宣传
  • 网站建设的基础企业排名优化公司
  • 个人网站模板怎么做百度搜索推广是什么
  • 自治区住房和城乡建设部网站seo网站内容优化
  • wordpress垃圾评论插件某网站seo诊断分析
  • 国际新闻网seo公司推广
  • 网站前端建设报价单网站seo入门基础教程
  • 网址导航类网站如何做推广三只松鼠搜索引擎营销案例
  • 电脑传奇游戏哪个好玩seo的推广技巧
  • web网站托管方案网络营销渠道策略有哪些
  • asp做网站策划书搜索引擎优化中的步骤包括
  • 西安做北郊做网站百度关键词热度排名
  • 怎么做一个网上商城seo网站关键词优化方法
  • 好的网站制作平台搜索引擎分哪三类
  • 网络营销的发展趋势抖音seo查询工具
  • 贵阳平台网站建设沈阳今天刚刚发生的新闻
  • 东莞今天特大新闻seo案例分析及解析
  • 医院网站建设的话术百度快照收录入口
  • 模板网站怎么用昆明seo工资
  • 政府网站普查 怎么做好网站制作公司