LeetCode--No.70--Climbing Stairs
来源:互联网 发布:阿里巴巴能走淘宝联盟 编辑:程序博客网 时间:2024/04/29 08:42
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?
Subscribe to see which companies asked this question
方法一:递归很简单
public class Solution { public int climbStairs(int n) { if(n==1) return 1; else if(n == 2) return 2; else return climbStairs(n-1) + climbStairs(n-2); }}方法二:非递归
public class Solution { public int climbStairs(int n) { int a = 0; int b = 1; int count = 0; for(int i = 0; i < n; i++){ count = a+b; a = b; b = count; } return count; }}
0 0
- Leetcode NO.70 Climbing Stairs
- LeetCode--No.70--Climbing Stairs
- LeetCode No.70 Climbing Stairs
- 【LeetCode】No.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
- Leetcode 70 Climbing Stairs
- leetcode 70:Climbing Stairs
- Leetcode #70 Climbing Stairs
- 与 so 有关的一个长年大坑
- 关于Android的.so文件你所需要知道的
- Android开发实践:使用Service还是Thread
- makefile中常用函数
- 初学者在java学习中常见的30个问题
- LeetCode--No.70--Climbing Stairs
- 条件随机场(CRF)— 绪论
- Elasticsearch Java API(七)--多级嵌套搜索
- 程序设计入门——C语言笔记(第4周-第5周)
- windows 下 再次安装mysql 时遇到1067错误
- Docker容器的数据管理
- Support NDK in Android studio.
- 关于android在嵌入式开发中遇到的问题解析
- Leetcode Search Insert Position