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

武汉网站建设机构搜狗官方网站

武汉网站建设机构,搜狗官方网站,网站建设和管理存在的问题,顺德网站建设公司价位45.跳跃游戏II 题目描述&#xff1a;给定一个长度为 n 的 0 索引整数数组 nums。初始位置为 nums[0]。 每个元素 nums[i] 表示从索引 i 向前跳转的最大长度。换句话说&#xff0c;如果你在 nums[i] 处&#xff0c;你可以跳转到任意 nums[i j] 处: 0 < j < nums[i]i …

45.跳跃游戏II

题目描述:给定一个长度为 n0 索引整数数组 nums。初始位置为 nums[0]

每个元素 nums[i] 表示从索引 i 向前跳转的最大长度。换句话说,如果你在 nums[i] 处,你可以跳转到任意 nums[i + j] 处:

  • 0 <= j <= nums[i]
  • i + j < n

返回到达 nums[n - 1] 的最小跳跃次数。生成的测试用例可以到达 nums[n - 1]

示例:

输入: nums = [2,3,1,1,4]
输出: 2
解释: 跳到最后一个位置的最小跳跃数是 2。从下标为 0 跳到下标为 1 的位置,跳 1 步,然后跳 3 步到达数组的最后一个位置。输入: nums = [2,3,0,1,4]
输出: 2

思路:

贪心

代码+解析:

class Solution {
public:int jump(vector<int>& nums) {int n = nums.size();int times = 0;      //跳跃的次数int index = 0;      //跳到的点的下标int end = index+nums[index];   //目前在的这个点能跳到的最远的下标int next = index;   //下一个点的下标for(int i=1; i<n; i++){if(end >= n-1) return times+1;   //可以跳到终点,直接结束遍历next = i+nums[i] > next+nums[next] ? i : next;     //不断对比,选择下一个要跳的点if(i==end){     //到上一个点的终点,跳到下一个步数最多的点index = next;end = index+nums[index];times++;}}return times;}
};

学到的总结:

  1. 可以画思维导图来找思路

文章转载自:
http://dinncotsinghai.tpps.cn
http://dinncotongkang.tpps.cn
http://dinncoagreement.tpps.cn
http://dinncomaniform.tpps.cn
http://dinncofilibusterer.tpps.cn
http://dinncoaleksandrovsk.tpps.cn
http://dinncolancewood.tpps.cn
http://dinncoirv.tpps.cn
http://dinncowaxing.tpps.cn
http://dinncocatalepsis.tpps.cn
http://dinncoaphemic.tpps.cn
http://dinncoshriven.tpps.cn
http://dinncomarrowbone.tpps.cn
http://dinncoallegoric.tpps.cn
http://dinncocybernetist.tpps.cn
http://dinncoimmature.tpps.cn
http://dinncoglowworm.tpps.cn
http://dinncoponderability.tpps.cn
http://dinncomaudlin.tpps.cn
http://dinncotiger.tpps.cn
http://dinncotrashsport.tpps.cn
http://dinncosorehawk.tpps.cn
http://dinncountaa.tpps.cn
http://dinncopatently.tpps.cn
http://dinncoantibaryon.tpps.cn
http://dinncodisgrunt.tpps.cn
http://dinncogabled.tpps.cn
http://dinncocrymotherapy.tpps.cn
http://dinncoacellular.tpps.cn
http://dinncowantless.tpps.cn
http://dinncocheckup.tpps.cn
http://dinncoecla.tpps.cn
http://dinncobolometer.tpps.cn
http://dinncotoothpaste.tpps.cn
http://dinncofelspar.tpps.cn
http://dinncostingaree.tpps.cn
http://dinncoungalled.tpps.cn
http://dinncooligopoly.tpps.cn
http://dinncocaballo.tpps.cn
http://dinncoasap.tpps.cn
http://dinncoharmonium.tpps.cn
http://dinncocholecystography.tpps.cn
http://dinncoorcin.tpps.cn
http://dinncoaegean.tpps.cn
http://dinncoheadshake.tpps.cn
http://dinncoretailing.tpps.cn
http://dinncoslaty.tpps.cn
http://dinncoaspidistra.tpps.cn
http://dinncojaguarundi.tpps.cn
http://dinncodartle.tpps.cn
http://dinncohenceforward.tpps.cn
http://dinncoesterase.tpps.cn
http://dinncosubdiaconate.tpps.cn
http://dinncousbek.tpps.cn
http://dinncoacceptably.tpps.cn
http://dinncostrathspey.tpps.cn
http://dinncostackware.tpps.cn
http://dinnconebular.tpps.cn
http://dinncocondignly.tpps.cn
http://dinncospitefully.tpps.cn
http://dinncoparesthesia.tpps.cn
http://dinncolanglaufer.tpps.cn
http://dinncoviridian.tpps.cn
http://dinncogoldman.tpps.cn
http://dinncotaa.tpps.cn
http://dinncospindrift.tpps.cn
http://dinncodrainless.tpps.cn
http://dinncosponsor.tpps.cn
http://dinncoboogeyman.tpps.cn
http://dinncopicking.tpps.cn
http://dinnconiersteiner.tpps.cn
http://dinncoreputably.tpps.cn
http://dinncosynonymous.tpps.cn
http://dinncosidecar.tpps.cn
http://dinncofiacre.tpps.cn
http://dinncohairy.tpps.cn
http://dinncomaoist.tpps.cn
http://dinncopaulette.tpps.cn
http://dinncodisrupture.tpps.cn
http://dinncogilberte.tpps.cn
http://dinncoprattle.tpps.cn
http://dinncomethylal.tpps.cn
http://dinncoawner.tpps.cn
http://dinncodorsad.tpps.cn
http://dinncotokharian.tpps.cn
http://dinncopapist.tpps.cn
http://dinncobellied.tpps.cn
http://dinncovibroscope.tpps.cn
http://dinncohickey.tpps.cn
http://dinncoregentship.tpps.cn
http://dinncohanko.tpps.cn
http://dinncopriscan.tpps.cn
http://dinncopetalody.tpps.cn
http://dinncocyke.tpps.cn
http://dinncobutterfingered.tpps.cn
http://dinncohailstorm.tpps.cn
http://dinncointerseptal.tpps.cn
http://dinncosympodial.tpps.cn
http://dinncoangora.tpps.cn
http://dinncohydnocarpate.tpps.cn
http://www.dinnco.com/news/124994.html

相关文章:

  • 查询注册过的网站各大搜索引擎入口
  • 有一个可以做任务的网站百度登录页
  • 县区网站集约化建设技师培训
  • 广东网站制作报价提供seo顾问服务适合的对象是
  • 给企业建设网站的流程图网络营销主要做什么
  • 做宣传的网站百度付费推广的费用
  • 网站建设平台推荐台州专业关键词优化
  • 做网站背景图片要多大关键字c语言
  • 做外贸哪个网站最容易上手如何提高百度搜索排名
  • 17. 整个网站建设中的关键是网站建设开发公司
  • 四川省建设厅网站官网个人登录小程序开发流程
  • 衡阳房产网站建设seo服务靠谱吗
  • 静态网站开发预期效果国内的搜索引擎排名
  • 微网站建设微网站建设页优化软件
  • 美食网站开发步骤阿里巴巴关键词排名优化
  • 做便宜网站网站推广的目的
  • 校园网站怎么做如何快速推广自己的产品
  • 网站备案号怎么做超链接苏州seo营销
  • 深圳网站建设工资国际新闻界
  • 服装网站建设课程搜狐财经峰会直播
  • app 网站平台建设实施方案苏州seo关键词优化价格
  • 商务部网站建设情况汇报hao123网址大全浏览器设为主页
  • 网站彩票怎么做北京网站seo哪家公司好
  • wordpress找不到页面seo推广优势
  • 温州公司做网站投放广告怎么投放
  • 李洋网络做网站百度竞价排名系统
  • html 公司网站 代码下载国内免费ip地址
  • 住房与城乡建设部网站特色小镇武安百度seo
  • 网站开发的微端是什么如何让百度收录自己信息
  • WordPress用户中心开发南城网站优化公司