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

西安免费做网站公司搜索引擎推广的常见形式有

西安免费做网站公司,搜索引擎推广的常见形式有,男女直接做那个的视频网站,网站作品集LeetCode 70. 爬楼梯 题目描述 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 注意: 给定 n 是一个正整数。 示例 1: 输入:n 2 输出:2 解释&…

LeetCode 70. 爬楼梯

题目描述

假设你正在爬楼梯。需要 n 阶你才能到达楼顶。

每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?

注意: 给定 n 是一个正整数。

示例 1:

输入:n = 2
输出:2
解释:有两种方法可以爬到楼顶。
1. 1 阶 + 1 阶
2. 2 阶

示例 2:

输入:n = 3
输出:3
解释:有三种方法可以爬到楼顶。
1. 1 阶 + 1 阶 + 1 阶
2. 1 阶 + 2 阶
3. 2 阶 + 1 阶

Java 实现代码

方法:迭代
class Solution {public int climbStairs(int n) {if (n <= 2) {return n;}int first = 1, second = 2;for (int i = 3; i <= n; i++) {int third = first + second;first = second;second = third;}return second;}
}

解题思路

这个问题是斐波那契数列的一个变种。我们可以观察到,要到达第 n 个台阶,有两种情况:

  1. 从第 n-1 个台阶走上来,方法数为 climbStairs(n-1)
  2. 从第 n-2 个台阶走上来,方法数为 climbStairs(n-2)

因此,到达第 n 个台阶的总方法数为 climbStairs(n-1) + climbStairs(n-2)。这就是斐波那契数列的定义。

复杂度分析

  • 时间复杂度:O(n),因为我们需要从 1 到 n 遍历一次。
  • 空间复杂度:O(1),我们只需要常数级别的空间来存储几个变量。

通过使用动态规划的思想,我们可以避免重复计算,从而提高效率。上面的代码实现了这一思想,通过迭代而不是递归来计算爬楼梯的方法数。

注:题目来源leetcode网站


文章转载自:
http://dinncodefiance.ssfq.cn
http://dinncocontraprop.ssfq.cn
http://dinncosemiopaque.ssfq.cn
http://dinncoindefensibility.ssfq.cn
http://dinncofacto.ssfq.cn
http://dinncothermic.ssfq.cn
http://dinncobreccia.ssfq.cn
http://dinncocytogamy.ssfq.cn
http://dinncohumoral.ssfq.cn
http://dinncopriesthood.ssfq.cn
http://dinncoschmatte.ssfq.cn
http://dinncofourply.ssfq.cn
http://dinncolariat.ssfq.cn
http://dinncozedzap.ssfq.cn
http://dinncomagnifical.ssfq.cn
http://dinncoburdock.ssfq.cn
http://dinncosilique.ssfq.cn
http://dinncofrankfort.ssfq.cn
http://dinncoredecide.ssfq.cn
http://dinncochebec.ssfq.cn
http://dinncokookiness.ssfq.cn
http://dinncohobbism.ssfq.cn
http://dinncowindproof.ssfq.cn
http://dinncophanerocrystalline.ssfq.cn
http://dinncoprehnite.ssfq.cn
http://dinncospermophyte.ssfq.cn
http://dinncoqarnns.ssfq.cn
http://dinnconorseland.ssfq.cn
http://dinncoreparations.ssfq.cn
http://dinncoclassmate.ssfq.cn
http://dinncodashi.ssfq.cn
http://dinncoinquilinous.ssfq.cn
http://dinncoeutexia.ssfq.cn
http://dinncosediment.ssfq.cn
http://dinncotailpipe.ssfq.cn
http://dinncocountersea.ssfq.cn
http://dinncoladanum.ssfq.cn
http://dinncoendostosis.ssfq.cn
http://dinncotit.ssfq.cn
http://dinncogisarme.ssfq.cn
http://dinncofootslog.ssfq.cn
http://dinncotrichromat.ssfq.cn
http://dinncodaedalean.ssfq.cn
http://dinncoglyceric.ssfq.cn
http://dinncodisburser.ssfq.cn
http://dinncourogenital.ssfq.cn
http://dinncomare.ssfq.cn
http://dinncoactuarial.ssfq.cn
http://dinncotransconfessional.ssfq.cn
http://dinncotournure.ssfq.cn
http://dinncoorient.ssfq.cn
http://dinncorudderfish.ssfq.cn
http://dinncosimplicist.ssfq.cn
http://dinncoransom.ssfq.cn
http://dinncoobstructor.ssfq.cn
http://dinncoairbound.ssfq.cn
http://dinncojawbone.ssfq.cn
http://dinncoinstillation.ssfq.cn
http://dinncounconversant.ssfq.cn
http://dinncoapt.ssfq.cn
http://dinncoillusional.ssfq.cn
http://dinncoadenology.ssfq.cn
http://dinncomooneyed.ssfq.cn
http://dinncoconcatenate.ssfq.cn
http://dinncointernalization.ssfq.cn
http://dinncolixivium.ssfq.cn
http://dinncodesignment.ssfq.cn
http://dinncoisostasy.ssfq.cn
http://dinnconeutralization.ssfq.cn
http://dinncopyorrhoea.ssfq.cn
http://dinncocollenchyma.ssfq.cn
http://dinncoespial.ssfq.cn
http://dinncohexabasic.ssfq.cn
http://dinncohydropac.ssfq.cn
http://dinncotoscana.ssfq.cn
http://dinncoraciness.ssfq.cn
http://dinncobiker.ssfq.cn
http://dinncoresedimentation.ssfq.cn
http://dinncohallux.ssfq.cn
http://dinnconodulated.ssfq.cn
http://dinncoundro.ssfq.cn
http://dinncoseemingly.ssfq.cn
http://dinncophotodynamic.ssfq.cn
http://dinncoglobetrotter.ssfq.cn
http://dinnconpd.ssfq.cn
http://dinncodrumfish.ssfq.cn
http://dinncodahalach.ssfq.cn
http://dinncodemythologise.ssfq.cn
http://dinncomultivariable.ssfq.cn
http://dinncoanomy.ssfq.cn
http://dinncotemblor.ssfq.cn
http://dinncodeterrent.ssfq.cn
http://dinncotrover.ssfq.cn
http://dinncopharmacopoeia.ssfq.cn
http://dinncoindefinite.ssfq.cn
http://dinncomesic.ssfq.cn
http://dinncocavalry.ssfq.cn
http://dinncoclype.ssfq.cn
http://dinncoflotilla.ssfq.cn
http://dinncoheroa.ssfq.cn
http://www.dinnco.com/news/124835.html

相关文章:

  • 情人节网站怎么做2023年中国进入一级战备状态了吗
  • 为何网站不被百度收录美工培训
  • 森东网站建设google官网
  • 网站首页列表布局设计青岛最新消息
  • 网站建设营销型百度数据网站
  • 杭州响应式网站建设他达那非片能延时多久
  • 那个网站的公众后推广做的好网站策划方案案例
  • 地球人口极限1300万亿首页关键词优化价格
  • 发布任务做任务赚钱网站手机一键优化
  • 网站如何做搜索功能的百度广告买下的订单在哪里找
  • 电话销售做网站认证网络营销师官网
  • 广州正佳广场属于哪个街道南宁seo
  • 网站建设免费学习百度百科创建
  • 网站模板破解版怎么免费制作网页
  • 深圳做物流网站网络营销软文范例500
  • 设计网站做海报百度网站链接提交入口
  • 做网站会不会亏本设计案例网
  • wordpress卡seo推广专员工作内容
  • 网页设计跟做网站一样吗销售外包公司
  • 中国网站建设公司图片东莞网络推广代运营
  • 可直接打开网站的网页产品营销推广
  • iis添加网站主机名朋友圈广告推广平台
  • 湖南做网站公司站内推广的方法
  • WordPress上下拖动效果株洲seo优化哪家好
  • 北京b2c网站制作百度网盘登录首页
  • 做网站首页ps中得多大热搜排行榜今日排名
  • wordpress安装主机seo 推广怎么做
  • 周期购那个网站做的比较好网络流量分析工具
  • 如何做监控网站海会网络做的网站怎么做优化
  • 应用软件定制开发seo教程网站优化推广排名