Leetcode-70. Climbing Stairs
来源:互联网 发布:网易smtp服务器 端口 编辑:程序博客网 时间:2024/04/18 04:09
题目介绍
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?
解法
思路:
a. n==0, f(n) = 1;
b. 当爬到第n层时,f(n) = f(n-1)+f(n-2);分别代表从第n-1层爬1步+第n-2层爬2步;也就是fibonacci.
int climbStairs(int n) { int first=1,second=1; int res; if(n==0||n==1){ return 1; } n = n-1; //计算次数 while(n--){ res = first+second; first = second; second = res; } return res; }
0 0
- [LeetCode]70.Climbing Stairs
- LeetCode --- 70. Climbing Stairs
- [Leetcode] 70. Climbing Stairs
- [leetcode] 70.Climbing Stairs
- [leetCode]70. Climbing Stairs
- 70. Climbing Stairs LeetCode
- [LeetCode]70. Climbing Stairs
- 【LeetCode】70. Climbing Stairs
- leetcode 70. Climbing Stairs
- leetcode 70. Climbing Stairs
- LeetCode *** 70. Climbing Stairs
- 【LeetCode】70. Climbing Stairs
- LeetCode 70. Climbing Stairs
- leetcode 70. Climbing Stairs
- [LeetCode]70. Climbing Stairs
- 【LeetCode】70. Climbing Stairs
- LeetCode 70. Climbing Stairs
- #leetcode#70.Climbing Stairs
- solve mass matrix in matlab
- ubuntu中将自己用户修改为root权限
- Study TypeScript《1、基础数据类型》
- Oracle导入大数据
- 137. Single Number II
- Leetcode-70. Climbing Stairs
- activity去掉标题和状态栏
- Codeforces 653A: Bear and Three Balls(技巧,水)
- Web 端 URL 的处理
- C++设计模式——单例模式
- 事务概述
- JavaScript强化教程-列表的动态增加元素
- PL/SQL-存储过程、函数
- Xms Xmx PermSize MaxPermSize的含义