多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > 綜合技術(shù) > leetcode 70 Climbing Stairs

leetcode 70 Climbing Stairs

來源:程序員人生   發(fā)布時(shí)間:2015-09-07 08:19:15 閱讀次數(shù):3199次

Climbing Stairs
                     

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Hide Tags
Dynamic Programming



這個(gè)題面試題還是比較常見的
討論的帖子:
https://leetcode.com/discuss/2809/easy-solutions-for-suggestions

原理:

This problem is a Fibonacci problem. F(n)=F(n⑴)+F(n⑵); Solving this problem by recursion ,we will do a lot of same recursion. Example: F(10)=F(9)+F(8); F(9)=F(8)+F(7); we calculate F(8) twice,when n is large,this will increase as a rate of n's exponent.

So a more efficient way to solve this problem is from Bottom to Top. Calculate F(0) ,F(1); then F(2).........

人生ac最快的代碼:
class Solution { public: int climbStairs(int n) { int stepone = 0; int steptwo = 1; int sum = 0; for(int i = 0;i<n;i++) { sum = stepone + steptwo; stepone = steptwo; steptwo = sum; } return sum; } };





DP算法求解:
https://leetcode.com/discuss/16275/my-dp-solution-using-c⑷-ms

簡(jiǎn)潔的代碼:
https://leetcode.com/discuss/31848/1ms-in-c-and⑵ms-in-c-optimal-space-no-temp-value

遞歸:
https://leetcode.com/discuss/28383/simple-and-clear⑵ms-solution-in-c-without-recursion

python:

https://leetcode.com/discuss/25378/this-is-essentially-a-fibonacci-sequence

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 成人免费视频在 | 国产视频欧美 | 欧美整片完整片视频在线 | 韩日精品 | 最近中文字幕高清mv免费 | 女女同性一区二区三区四区 | 色综合天天综合网国产成人网 | 国产高清国产精品国产k | 波多野一区二区 | 久久久久久岛国免费网站 | 日韩欧美一区二区三区在线视频 | 欧美黄色片免费观看 | www成人在线观看 | www.xxx欧美| 久久精品国产精品亚洲综合 | 精品免费久久久久国产一区 | 男女一区二区三区免费 | 日本护士18一25 | 欧美亚洲激情视频 | 日本免费区 | 精品国产日韩一区三区 | 国产精品99久久久久久人 | 欧美18videosex性欧 | 国产精品视频永久免费播放 | 欧美日韩一二三区 | 自拍偷拍欧美亚洲 | 欧美亚洲高清日韩成人 | 国内在线精品 | 精品国产一区二区三区久久影院 | 欧美一区二区三区在观看 | 波多野结衣gvg-238 | 性久久久久久 | 国产h视频在线 | 日韩欧美中文字幕出 | 性videos另类hdwww | 最新国产大片高清视频 | 欧美一区二区三区男人的天堂 | 最近最新手机中文字幕在线看 | 日本69av| 精品亚洲综合久久中文字幕 | 成人国产在线不卡视频 |