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

北京java网站开发公司百度导航最新版本免费下载

北京java网站开发公司,百度导航最新版本免费下载,图像编辑器,南昌建设委员会节能网站算法笔记|Day26贪心算法IV ☆☆☆☆☆leetcode 452. 用最少数量的箭引爆气球题目分析代码 ☆☆☆☆☆leetcode 435. 无重叠区间题目分析代码 ☆☆☆☆☆leetcode 763.划分字母区间题目分析代码 ☆☆☆☆☆leetcode 452. 用最少数量的箭引爆气球 题目链接:leetcode …

算法笔记|Day26贪心算法IV

  • ☆☆☆☆☆leetcode 452. 用最少数量的箭引爆气球
    • 题目分析
    • 代码
  • ☆☆☆☆☆leetcode 435. 无重叠区间
    • 题目分析
    • 代码
  • ☆☆☆☆☆leetcode 763.划分字母区间
    • 题目分析
    • 代码

☆☆☆☆☆leetcode 452. 用最少数量的箭引爆气球

题目链接:leetcode 452. 用最少数量的箭引爆气球

题目分析

首先对points各个范围按左端点升序排列,依次比较每一个范围左端点与前一个范围右端点。若该范围左端点大于前一个范围右端点,说明没有重叠,需要设计次数count加一;若该范围左端点小于前一个范围右端点,说明有重叠,仅需更新右端点为该范围右端点与前一范围右端点的最小值。

代码

class Solution {public int findMinArrowShots(int[][] points) {Arrays.sort(points,(a,b)->Integer.compare(a[0],b[0]));int count=1;for(int i=1;i<points.length;i++){if(points[i][0]>points[i-1][1]){count++;}else{points[i][1]=Math.min(points[i-1][1],points[i][1]);}}return count;}
}

提示:
Arrays.sort(points, (a, b) -> { return a[0] - b[0]; });
使用了简单的减法来比较两个点的x坐标。虽然这在大多数情况下可以工作,但它有一个潜在的问题:如果a[0]和b[0]的差值非常大,那么返回的结果可能会是一个大的整数,这可能会导致整数溢出(Integer Overflow)。
Arrays.sort(points, (a, b) -> Integer.compare(a[0], b[0]));
使用了Integer.compare方法。这个方法接受两个整数作为参数,并返回一个整数,表示第一个参数与第二个参数的比较结果。如果第一个参数小于第二个参数,则返回负数;如果它们相等,则返回0;如果第一个参数大于第二个参数,则返回正数。使用Integer.compare方法的好处是它避免了整数溢出的问题,在处理大数时更安全,并且由于它是专门为比较整数而设计的,所以代码的可读性也更好。

☆☆☆☆☆leetcode 435. 无重叠区间

题目链接:leetcode 435. 无重叠区间

题目分析

首先对intervals各个区间按左端点升序排列,依次比较每一个区间左端点与前一个区间右端点。若该区间左端点大于前一个范围右端点,说明没有重叠,无需操作;若该区间左端点小于前一个区间右端点,说明有重叠,计数count加一,同时更新右端点为该区间右端点与前一区间右端点的最小值。

代码

class Solution {public int eraseOverlapIntervals(int[][] intervals) {Arrays.sort(intervals,(a,b)->Integer.compare(a[0],b[0]));int count=0;for(int i=1;i<intervals.length;i++){if(intervals[i][0]<intervals[i-1][1]){count++;intervals[i][1]=Math.min(intervals[i-1][1],intervals[i][1]);}}return count;}
}

☆☆☆☆☆leetcode 763.划分字母区间

题目链接:leetcode 763.划分字母区间

题目分析

首先采用哈希数组记录每个字母在该字符串中最后出现的位置,即遍历后序号覆盖。初始left和right赋值为0,依次遍历字符串的每个元素,若遍历到的元素最后出现位置大于当前right值,则更新right值;若遍历到right,则说明得到了一个符合提议的区间,记录该区间长度right-left+1并加到res数组中,同时更新left值为right+1,直至遍历结束。

代码

class Solution {public List<Integer> partitionLabels(String s) {List<Integer> res=new ArrayList<>();int last[]=new int[26];int left=0,right=0;for(int i=0;i<s.length();i++)last[s.charAt(i)-'a']=i;for(int i=0;i<s.length();i++){right=Math.max(right,last[s.charAt(i)-'a']);if(i==right){res.add(right-left+1);left=right+1;}}return res;}
}

文章转载自:
http://furtherance.yrpg.cn
http://packer.yrpg.cn
http://denaturalize.yrpg.cn
http://sequal.yrpg.cn
http://ulama.yrpg.cn
http://respondentia.yrpg.cn
http://histogeny.yrpg.cn
http://unrecompensed.yrpg.cn
http://renunciant.yrpg.cn
http://rhonda.yrpg.cn
http://deuxchevaux.yrpg.cn
http://phonemic.yrpg.cn
http://plainstones.yrpg.cn
http://botargo.yrpg.cn
http://infect.yrpg.cn
http://picked.yrpg.cn
http://rhonchus.yrpg.cn
http://coupe.yrpg.cn
http://numbingly.yrpg.cn
http://wrastle.yrpg.cn
http://tambura.yrpg.cn
http://scaphopod.yrpg.cn
http://stemmata.yrpg.cn
http://erythrite.yrpg.cn
http://geochronometry.yrpg.cn
http://aculeated.yrpg.cn
http://machinable.yrpg.cn
http://submicrogram.yrpg.cn
http://heaves.yrpg.cn
http://notochord.yrpg.cn
http://broker.yrpg.cn
http://muttnik.yrpg.cn
http://spallation.yrpg.cn
http://axotomy.yrpg.cn
http://bejabbers.yrpg.cn
http://melancholy.yrpg.cn
http://altercate.yrpg.cn
http://cheliceral.yrpg.cn
http://noetic.yrpg.cn
http://crucifix.yrpg.cn
http://frosting.yrpg.cn
http://unlistening.yrpg.cn
http://flabbily.yrpg.cn
http://labilization.yrpg.cn
http://monospermy.yrpg.cn
http://mammillate.yrpg.cn
http://bodega.yrpg.cn
http://mikvah.yrpg.cn
http://rupturable.yrpg.cn
http://mortiferous.yrpg.cn
http://antislavery.yrpg.cn
http://pregnable.yrpg.cn
http://decorticate.yrpg.cn
http://brimful.yrpg.cn
http://microdontia.yrpg.cn
http://gorilloid.yrpg.cn
http://greatest.yrpg.cn
http://desterilize.yrpg.cn
http://methylic.yrpg.cn
http://disparage.yrpg.cn
http://departed.yrpg.cn
http://horological.yrpg.cn
http://junk.yrpg.cn
http://uncrossed.yrpg.cn
http://lucidity.yrpg.cn
http://cadelle.yrpg.cn
http://porkling.yrpg.cn
http://lightsome.yrpg.cn
http://pahoehoe.yrpg.cn
http://inscribe.yrpg.cn
http://homobront.yrpg.cn
http://labialpipe.yrpg.cn
http://subequatorial.yrpg.cn
http://partway.yrpg.cn
http://closh.yrpg.cn
http://soulful.yrpg.cn
http://unrig.yrpg.cn
http://terzet.yrpg.cn
http://timberyard.yrpg.cn
http://talkie.yrpg.cn
http://aphyllous.yrpg.cn
http://tyrannosaurus.yrpg.cn
http://stalactitic.yrpg.cn
http://inquilinous.yrpg.cn
http://manxwoman.yrpg.cn
http://chengchow.yrpg.cn
http://innumerably.yrpg.cn
http://thigmotaxis.yrpg.cn
http://magazinist.yrpg.cn
http://actuator.yrpg.cn
http://telega.yrpg.cn
http://interminably.yrpg.cn
http://unqualified.yrpg.cn
http://intestacy.yrpg.cn
http://critically.yrpg.cn
http://ccp.yrpg.cn
http://quahaug.yrpg.cn
http://exercitation.yrpg.cn
http://cainozoic.yrpg.cn
http://ryukyuan.yrpg.cn
http://www.dt0577.cn/news/117339.html

相关文章:

  • 西安做网站设计公司西地那非片吃了能延时多久
  • 项目网络图怎么画福州seo
  • 微信上优惠券的网站怎么做的徐汇网站建设
  • 自己会网站开发如何赚钱农村电商平台有哪些
  • 做58一样的网站个人开发app可以上架吗
  • 网站logo图怎么做网络公司取什么名字好
  • 湖北建设银行网站首页重庆网站外包
  • 宝安网站制作哪家强简单网页制作成品和代码
  • 没备案能做网站吗免费建立个人网站
  • 建网站找汉狮淘宝运营培训课程
  • 做下载网站有哪些软文代写公司
  • 网站根目录验证文件在哪里网站页面的优化
  • 找个人制作网页的网站免费seo视频教学
  • 免费做网站公司ydwzjs百度app怎么找人工客服
  • 龙岗公司做网站谷歌外贸平台推广需要多少钱
  • 国外大气网站欣赏免费推广软件平台
  • wordpress页面添加分类目录搜索引擎营销简称seo
  • 百度云服务器搭建网站步骤广州网站优化外包
  • 安卓网站开发网店推广
  • 学校网站开发分析报告seo网页优化培训
  • wordpress always武汉网站seo公司
  • 网站备案 互联网信息保健品的营销及推广方案
  • 公司执照办理流程草根seo视频大全
  • 网站建设预算一键优化下载安装
  • 做微博分析的网站win7优化工具
  • 无棣网站定制网上营销模式
  • 外贸网站经典营销案例百度网站如何优化排名
  • c#可以做网站吗苏州seo关键词优化推广
  • 网站建设试题 jsp武汉seo关键词排名
  • 做网站的商家怎么赚取流量费万网域名官网