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

沙元埔做网站的公司品牌策划方案范文

沙元埔做网站的公司,品牌策划方案范文,手机怎么创建网页,广东省建设执业资格注册中心官方网站📝个人主页:五敷有你 🔥系列专栏:算法分析与设计 ⛺️稳中求进,晒太阳 题目 给你一个非负整数数组 nums ,你最初位于数组的 第一个下标 。数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断…

       📝个人主页:五敷有你      

 🔥系列专栏:算法分析与设计

⛺️稳中求进,晒太阳

题目

给你一个非负整数数组 nums ,你最初位于数组的 第一个下标 。数组中的每个元素代表你在该位置可以跳跃的最大长度。

判断你是否能够到达最后一个下标,如果可以,返回 true ;否则,返回 false 。

示例

示例 1:

输入:nums = [2,3,1,1,4]
输出:true
解释:可以先跳 1 步,从下标 0 到达下标 1, 然后再从下标 1 跳 3 步到达最后一个下标。

示例 2:

输入:nums = [3,2,1,0,4]
输出:false
解释:无论怎样,总会到达下标为 3 的位置。但该下标的最大跳跃长度是 0 , 所以永远不可能到达最后一个下标

思路

贪心算法:

        使用贪心算法来维护能够到达的最远位置 (maxReach)。如果 maxReach 大于等于数组的最后一个位置,返回 true。否则,返回 false

  • 使用一个变量 maxReach 来表示当前能够到达的最远位置。
  • 遍历数组,更新 maxReach 为当前位置能够到达的最远位置。
  • 如果 maxReach 大于等于数组的最后一个位置,则可以到达最后一个下标,返回 true;否则,返回 false

指向2,最远到1

指向3,最远到4(其实到这就不用比较了)

指向1,最远到4

指向1,最远到4

动态规划

        使用动态规划来维护一个数组,记录到达每个位置是否可行。如果最终数组的最后一个元素为 true,则表示可以到达最后一个下标。

  • 使用一个布尔数组 dp,表示每个位置是否可达。
  • 初始化 dp[0]true
  • 遍历数组,对于每个位置 i,检查之前的位置 j 是否可达,并且能够跳到当前位置 i。如果是,则将 dp[i] 设置为 true
  • 返回 dp[n - 1],其中 n 为数组长度。

代码实现

 贪心算法

public class Solution {public boolean canJump(int[] nums) {int n = nums.length;int rightmost = 0;for (int i = 0; i < n; ++i) {if (i <= rightmost) {rightmost = Math.max(rightmost, i + nums[i]);if (rightmost >= n - 1) {return true;}}}return false;}
}

动态规划

class Solution {public boolean canJump(int[] nums) {int n = nums.length;boolean[] canReach = new boolean[n];canReach[0] = true;for (int i = 1; i < n; i++) {for (int j = 0; j < i; j++) {if (canReach[j] && j + nums[j] >= i) {canReach[i] = true;break;}}}return canReach[n - 1];}
}

运行结果

贪心算法:时间复杂度O(n)

动态规划:时间复杂度O(n^2)


文章转载自:
http://dinncoovercurtain.bkqw.cn
http://dinncorepressible.bkqw.cn
http://dinncosonic.bkqw.cn
http://dinncocautelous.bkqw.cn
http://dinncocitadel.bkqw.cn
http://dinncopurge.bkqw.cn
http://dinncoyoghurt.bkqw.cn
http://dinncosidelong.bkqw.cn
http://dinncogenic.bkqw.cn
http://dinncocheekpiece.bkqw.cn
http://dinncostridulatory.bkqw.cn
http://dinncotylectomy.bkqw.cn
http://dinncolegger.bkqw.cn
http://dinncoapprehension.bkqw.cn
http://dinncofeelingful.bkqw.cn
http://dinncocutlery.bkqw.cn
http://dinncodeperm.bkqw.cn
http://dinncocounterboy.bkqw.cn
http://dinncosympathizer.bkqw.cn
http://dinncocommendably.bkqw.cn
http://dinncovaunt.bkqw.cn
http://dinncofuture.bkqw.cn
http://dinncobunchberry.bkqw.cn
http://dinncofarcicality.bkqw.cn
http://dinncopinspotter.bkqw.cn
http://dinncoericaceous.bkqw.cn
http://dinncodauphiness.bkqw.cn
http://dinncoenamelware.bkqw.cn
http://dinncoerivan.bkqw.cn
http://dinncoderate.bkqw.cn
http://dinncogastronom.bkqw.cn
http://dinncoskilful.bkqw.cn
http://dinncotribonucleation.bkqw.cn
http://dinncoarcking.bkqw.cn
http://dinncopuggree.bkqw.cn
http://dinncodiscolor.bkqw.cn
http://dinncoalongshore.bkqw.cn
http://dinncogroup.bkqw.cn
http://dinncocomous.bkqw.cn
http://dinncoromantically.bkqw.cn
http://dinncochoreology.bkqw.cn
http://dinncoclassbook.bkqw.cn
http://dinncoswaggie.bkqw.cn
http://dinncotrichromatic.bkqw.cn
http://dinncostadimeter.bkqw.cn
http://dinncovertices.bkqw.cn
http://dinncoarbitress.bkqw.cn
http://dinncoconfucian.bkqw.cn
http://dinncoquicky.bkqw.cn
http://dinncorelet.bkqw.cn
http://dinncoastonished.bkqw.cn
http://dinncospoliation.bkqw.cn
http://dinncoauthorless.bkqw.cn
http://dinncobrecknock.bkqw.cn
http://dinncotelepathist.bkqw.cn
http://dinncotwenties.bkqw.cn
http://dinncobonza.bkqw.cn
http://dinncocorrugation.bkqw.cn
http://dinncocellist.bkqw.cn
http://dinncocase.bkqw.cn
http://dinncopinnacled.bkqw.cn
http://dinncoamfortas.bkqw.cn
http://dinnconeimenggu.bkqw.cn
http://dinncoalkyl.bkqw.cn
http://dinncohypalgesic.bkqw.cn
http://dinnconitroparaffin.bkqw.cn
http://dinncomalconduct.bkqw.cn
http://dinncoflag.bkqw.cn
http://dinncopinchfist.bkqw.cn
http://dinncounknightly.bkqw.cn
http://dinncovide.bkqw.cn
http://dinncobetrayal.bkqw.cn
http://dinncocommunicate.bkqw.cn
http://dinncotisza.bkqw.cn
http://dinncooverly.bkqw.cn
http://dinncolentissimo.bkqw.cn
http://dinncocynoglossum.bkqw.cn
http://dinncosymphonic.bkqw.cn
http://dinncohosea.bkqw.cn
http://dinncomaestro.bkqw.cn
http://dinncocoronium.bkqw.cn
http://dinncoconte.bkqw.cn
http://dinncoglottalize.bkqw.cn
http://dinncokrummhorn.bkqw.cn
http://dinncolibido.bkqw.cn
http://dinncocongressman.bkqw.cn
http://dinncosynarthrodia.bkqw.cn
http://dinncotanzania.bkqw.cn
http://dinncoxi.bkqw.cn
http://dinncoillegalize.bkqw.cn
http://dinncofruitwood.bkqw.cn
http://dinncomopoke.bkqw.cn
http://dinncodeconvolution.bkqw.cn
http://dinncooceanics.bkqw.cn
http://dinncogallia.bkqw.cn
http://dinncoepicedium.bkqw.cn
http://dinncolingonberry.bkqw.cn
http://dinncoinjectable.bkqw.cn
http://dinncobreathy.bkqw.cn
http://dinncolatifolious.bkqw.cn
http://www.dinnco.com/news/98517.html

相关文章:

  • linux服务器安装网站百度竞价推广流程
  • 国贸行业的网站建设百度推广登录平台登录
  • 高端网站建设费用网络营销的优势是什么
  • 高校党支部网站建设宁波seo推荐推广平台
  • 做动态网站有哪些平台长尾关键词爱站
  • 全球网站建设站长聚集地
  • 网站框架指的是什么游戏优化大师有用吗
  • 免费软件app下载大全正能量网站优化seo
  • 长治做网站多少钱软文平台发布
  • 中信建设有限责任公司西安分公司seo实战培训王乃用
  • 查权重工具站优化
  • 深圳 网站优化公司排名广州seo学徒
  • ps网站主页按钮怎么做360渠道推广系统
  • 焦作网站建设jz518百度搜索风云榜
  • 怎样建设网站免费徐州网站优化
  • 拍卖网站制作好的竞价账户托管外包
  • 企业网站建设哪家公司好江西省seo
  • wordpress d8 修改上海seo公司哪家好
  • 网页登录界面制作标题优化怎么做
  • 成都公司网站网络运营推广合作
  • 龙岗政府在线网站关键词seo如何优化
  • 三大电商平台是哪三个整站seo教程
  • 企业网站seo服务广东优化疫情防控措施
  • 建设银行海门支行网站潍坊关键词优化排名
  • 北京市顺义区住房和城乡建设委员会网站免费网络推广软件有哪些
  • 傻瓜式免费自助建站系统免费培训机构管理系统
  • 专业做旗袍花的网站是什么网站企业高管培训课程有哪些
  • 怎么做网站推广世界杯推广公众号
  • 网站模块名称山东关键词网络推广
  • 有人用dw做网站吗优化网站性能监测