博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Climbing Stairs
阅读量:4613 次
发布时间:2019-06-09

本文共 562 字,大约阅读时间需要 1 分钟。

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?

class Solution {public:    int climbStairs(int n) {        // Start typing your C/C++ solution below        // DO NOT write int main() function        int dp1 = 1, dp2 = 2,dp;        dp = n == 1 ? dp1 : dp2;        for(int i = 3; i <= n; i++){            dp = dp1 + dp2;            dp1 = dp2;            dp2 = dp;        }        return dp;    }};

 

转载于:https://www.cnblogs.com/kwill/p/3182930.html

你可能感兴趣的文章
矩阵乘法快速幂 cojs 1717. 数学序列
查看>>
设计模式理解(八)结构型——装饰者模式(记得加上UML图 --- 未完)
查看>>
iframe实现局部更新
查看>>
java 1.5 自动拆箱和装箱的注意事项
查看>>
python3 smtp 自动发送邮件
查看>>
七分频占空比为50%电路设计
查看>>
使用ASP.NET AJAX ,遇到Sys 未定义解决方法
查看>>
jenkins 每个月1号到7号 一天执行一次
查看>>
HTML页面生成ASPX页面
查看>>
Linux程序设计(第4版)
查看>>
PHP中的11个魔术方法总结:__construct,、__destruct、__call等
查看>>
Python3学习笔记十三
查看>>
垃圾回收的常见算法
查看>>
什么是obj文件?
查看>>
linux中 tar .gz bz2 xz 怎么用 解压
查看>>
旧题再做【bzoj2287】【[pojchallenge]消失之物】分治背包
查看>>
开源视频服务软件MJPG-streamer移植
查看>>
poi--读取不同类型的excel表格
查看>>
网页的构造块
查看>>
linux 命令大全
查看>>