T70 爬楼梯

桌桌 2022-8-12 206 8/12

题目描述:

T70 爬楼梯

解题思路:

对于每个楼梯状态,我只需要知道之前的一个和之前两个楼梯有多少种方法然后将他们加起来就可以了

代码如下:

class Solution:
   def climbStairs(self, n: int) -> int:
       if n == 1:
           return 1
       mylist = [0 for i in range(n)]
       mylist[0] = 1
       mylist[1] = 2
       for i in range(2, n):
           mylist[i] = mylist[i-1]+mylist[i-2]
       return mylist[n-1]

结果如下:

T70 爬楼梯

- THE END -

桌桌

8月16日01:08

最后修改:2022年8月16日
0

非特殊说明,本博所有文章均为博主原创。

共有 7 条评论

  1. bitcoin

    Hiya very nice site!! Man .. Beautiful .. Wonderful .. Theron Martini

  2. bitcoin

    I have read so many posts about the blogger lovers but this article is in fact a good article, keep it up. Pablo Wrightsman

  3. king putin

    These are genuinely great ideas in concerning blogging. Mose Husseini

  4. king putin

    Looking forward to reading more. Great blog article. Much obliged. Sam Belcourt

  5. Loveme

    One can learn something new here everyday. Im a regular for most of those blogs, but still didnt know about a couple of them. Faustino Nein

  6. Anna94 wants to trade nude pics with you

    I truly appreciate this post. Well, I have put together a long list. Interesting content. I truly appreciate this post. Dustin Carathers

  7. sikis

    Very interestting details you have mentioned, appreciate it for putting up. Darrell Soboleski