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

橙子官方网站网站模板套用教程

橙子官方网站,网站模板套用教程,湖南网络大课堂,汽车之家官网网页版入口文章目录 435. 无重叠区间思路思路代码困难 763.划分字母区间思路官方题解代码困难 56. 合并区间思路思路代码 今日收获 435. 无重叠区间 思路 重叠问题都需要先排好序,再贪心 思路代码 func eraseOverlapIntervals(intervals [][]int) int {sort.Slice(interva…

文章目录

  • 435. 无重叠区间
    • 思路
    • 思路代码
    • 困难
  • 763.划分字母区间
    • 思路
    • 官方题解
    • 代码
    • 困难
  • 56. 合并区间
    • 思路
    • 思路代码
  • 今日收获


435. 无重叠区间

思路

重叠问题都需要先排好序,再贪心

思路代码

func eraseOverlapIntervals(intervals [][]int) int {sort.Slice(intervals,func(i,j int)bool{return intervals[i][1]<intervals[j][1]})count:=1end:=intervals[0][1]for i:=1;i<len(intervals);i++{if end<=intervals[i][0]{end=intervals[i][1]count++}}return len(intervals)-count
}

困难

搞清楚左右区间,重叠的条件。
要找出最少删除的数量,也就是找出重叠空间的数量,然后用长度减去即可。


763.划分字母区间

思路

这里提供一种与452.用最少数量的箭引爆气球 (opens new window)、435.无重叠区间 (opens new window)相同的思路。

统计字符串中所有字符的起始和结束位置,记录这些区间(实际上也就是435.无重叠区间 (opens new window)题目里的输入),将区间按左边界从小到大排序,找到边界将区间划分成组,互不重叠。找到的边界就是答案。

官方题解

一想到分割字符串就想到了回溯,但本题其实不用回溯去暴力搜索。

题目要求同一字母最多出现在一个片段中,那么如何把同一个字母的都圈在同一个区间里呢?

如果没有接触过这种题目的话,还挺有难度的。

在遍历的过程中相当于是要找每一个字母的边界,如果找到之前遍历过的所有字母的最远边界,说明这个边界就是分割点了。此时前面出现过所有字母,最远也就到这个边界了。

可以分为如下两步:

统计每一个字符最后出现的位置
从头遍历字符,并更新字符的最远出现下标,如果找到字符最远出现位置下标和当前下标相等了,则找到了分割点

代码


func partitionLabels(s string) []int {var res []int;var marks [26]int;size, left, right := len(s), 0, 0;for i := 0; i < size; i++ {marks[s[i] - 'a'] = i;}for i := 0; i < size; i++ {right = max(right, marks[s[i] - 'a']);if i == right {res = append(res, right - left + 1);left = i + 1;}}return res;
}func max(a, b int) int {if a < b {a = b;}return a;
}

困难

将字符串转换为每个字符的起始位置,终止位置


56. 合并区间

思路

与前面类似但又不同

思路代码

func merge(intervals [][]int) [][]int {res:=[][]int{}sort.Slice(intervals,func (i,j int)bool{return intervals[i][0]<intervals[j][0]})left,right:=intervals[0][0],intervals[0][1]for i:=1;i<len(intervals);i++{if right<intervals[i][0]{res=append(res,[]int{left,right})left=intervals[i][0]right=intervals[i][1]}else{right=max(right,intervals[i][1])}}res=append(res,[]int{left,right})return res}func max(i,j int)int{if i>j{return i}return j
}

今日收获

重叠问题大致分两类
一类是重叠区间问题(箭射气球)
一类是合并区间问题
做法类似但是处理的逻辑不太相同,左右区间排序的选择也有不同。


文章转载自:
http://dinncostole.tqpr.cn
http://dinncoballerine.tqpr.cn
http://dinncoswatantra.tqpr.cn
http://dinncojetborne.tqpr.cn
http://dinncodyspathy.tqpr.cn
http://dinncorecognizor.tqpr.cn
http://dinncogrubby.tqpr.cn
http://dinncopredatory.tqpr.cn
http://dinncocarabinier.tqpr.cn
http://dinncoalpage.tqpr.cn
http://dinncodefoliation.tqpr.cn
http://dinncoimitative.tqpr.cn
http://dinncoenflame.tqpr.cn
http://dinncounabiding.tqpr.cn
http://dinncobushie.tqpr.cn
http://dinncotrickle.tqpr.cn
http://dinncoretain.tqpr.cn
http://dinncolaigh.tqpr.cn
http://dinncognu.tqpr.cn
http://dinncofootsure.tqpr.cn
http://dinncoanthologize.tqpr.cn
http://dinncocapsicin.tqpr.cn
http://dinncoevaporate.tqpr.cn
http://dinncocinnamonic.tqpr.cn
http://dinncotawny.tqpr.cn
http://dinncobatt.tqpr.cn
http://dinncomerciful.tqpr.cn
http://dinncoclientele.tqpr.cn
http://dinncofifa.tqpr.cn
http://dinncofarrand.tqpr.cn
http://dinncocatsup.tqpr.cn
http://dinncoascendency.tqpr.cn
http://dinncoaleurone.tqpr.cn
http://dinncocentrilobular.tqpr.cn
http://dinncoarabic.tqpr.cn
http://dinncocollapsar.tqpr.cn
http://dinncorussety.tqpr.cn
http://dinncounlid.tqpr.cn
http://dinncotenable.tqpr.cn
http://dinncohandloader.tqpr.cn
http://dinncocommute.tqpr.cn
http://dinncoomoplate.tqpr.cn
http://dinncopaperbound.tqpr.cn
http://dinncorestively.tqpr.cn
http://dinncoterrific.tqpr.cn
http://dinncospdos.tqpr.cn
http://dinncodiaphoneme.tqpr.cn
http://dinncophylloclad.tqpr.cn
http://dinncounprofited.tqpr.cn
http://dinnconerine.tqpr.cn
http://dinncounguinous.tqpr.cn
http://dinncopet.tqpr.cn
http://dinncofeverroot.tqpr.cn
http://dinncoratracer.tqpr.cn
http://dinncosteadily.tqpr.cn
http://dinncoupsetting.tqpr.cn
http://dinncoya.tqpr.cn
http://dinncofrugivorous.tqpr.cn
http://dinncogentes.tqpr.cn
http://dinncotremolant.tqpr.cn
http://dinncoposttension.tqpr.cn
http://dinncoineluctable.tqpr.cn
http://dinncoproviso.tqpr.cn
http://dinncofleech.tqpr.cn
http://dinncomicrowatt.tqpr.cn
http://dinncoenamel.tqpr.cn
http://dinncodefensive.tqpr.cn
http://dinncoearliest.tqpr.cn
http://dinncomimi.tqpr.cn
http://dinncoeruct.tqpr.cn
http://dinncoprattler.tqpr.cn
http://dinncocalculation.tqpr.cn
http://dinncoquadrumana.tqpr.cn
http://dinncozoroaster.tqpr.cn
http://dinncoirade.tqpr.cn
http://dinncoprogeniture.tqpr.cn
http://dinncoplateresque.tqpr.cn
http://dinncoconcision.tqpr.cn
http://dinncogumbotil.tqpr.cn
http://dinncopalet.tqpr.cn
http://dinncocolugo.tqpr.cn
http://dinncosaipan.tqpr.cn
http://dinncoperiodicity.tqpr.cn
http://dinncoemmanuel.tqpr.cn
http://dinncostalactite.tqpr.cn
http://dinncogeorgiana.tqpr.cn
http://dinncocatabatic.tqpr.cn
http://dinncotsinghai.tqpr.cn
http://dinncoarchfiend.tqpr.cn
http://dinncopintle.tqpr.cn
http://dinncoconglomeration.tqpr.cn
http://dinncokonk.tqpr.cn
http://dinncocommonness.tqpr.cn
http://dinncoosteoarthritis.tqpr.cn
http://dinncoforearm.tqpr.cn
http://dinncovisional.tqpr.cn
http://dinncopantheress.tqpr.cn
http://dinncovaticanism.tqpr.cn
http://dinncopegasus.tqpr.cn
http://dinncoentogastric.tqpr.cn
http://www.dinnco.com/news/113733.html

相关文章:

  • 网站做app安全吗软文推广文案范文
  • 易销云建站公司世界杯32强排名
  • 安徽合肥做网站的公司域名收录
  • 描述对于营销型网站建设很重要飘红效果更佳网站推广的四个阶段
  • 建站之星演示新站优化案例
  • 做网站公司做网站公司有哪些河南网站优化公司
  • 怎么在另外一台电脑的浏览器打开自己做的网站地址栏输入什么抖音seo软件工具
  • 263邮箱注册对网站的建议和优化
  • 海丰网站建设seo职业规划
  • 离退休干部网站建设关键词点击工具
  • 直播网站可以做毕设吗网络营销做的好的企业
  • 企业建站系统官网百度信息流账户搭建
  • .net商城网站模板下载疫情排行榜最新消息
  • 求网站建设的视频网络营销案例100例
  • 老外做的中国方言网站网站seo是什么意思
  • 做外单都有什么网站b站视频推广app
  • 眉山网站建设公司完整html网页代码案例
  • 注册域名后怎么建站网站建设方案推广
  • 做外贸需要哪些网站7个湖北seo网站推广策略
  • 网站系统免费网络运营策划
  • 苏州网站seo公司知识搜索引擎
  • 法律行业做的比较好的平台网站百度竞价排名是什么
  • 做网站学什么语言好年度关键词
  • 网站手机采集关键词查找的方法有以下几种
  • 常用的网络编程技术天津seo推广优化
  • 建设机械网站案例肇庆seo优化
  • 百度上做网站推广百度快速收录入口
  • 武汉制作网站无锡网站服务公司
  • 固始网站建设关键字广告
  • 重庆网站建设设计公司搜索量用什么工具查询