LeetCode - 70. 爬楼梯
2018-09-09 15:06
169 查看
70. 爬楼梯
class Solution { /** * f(n) 表示爬到第n层的方法数 * 第n层可由第n-1层迈1步到达 * 亦可由第n-2层迈2步到达 * 所以 f(n) = f(n-1) + f(n-2) * @param n * @return */ public int climbStairs(int n) { if (n == 1) { return 1; } if (n == 2) { return 2; } int a = 1, b = 2, c = 3; for (int i = 3; i <= n; ++ i) { c = a + b; a = b; b = c; } return c; } }
相关文章推荐
- LeetCode题库解答与分析——#70. 爬楼梯ClimbingStairs
- LeetCode 70. 爬楼梯
- Leetcode 70 Climbing Stairs 爬楼梯的方法(动态规划)
- 70.[Leetcode]Climbing Stairs
- Leetcode刷题记——70. Climbing Stairs(爬楼梯)
- [LeetCode] 70.爬楼梯
- [LeetCode] 70. Climbing Stairs
- leetcode70.[DP] Climbing Stairs My Submissions Question
- [Leetcode] climbing stairs 爬楼梯
- LeetCode Climbing Stairs 爬楼梯
- LeetCode-Climbing Stairs(爬楼梯问题)
- Leetcode 746. Min Cost Climbing Stairs 最小成本爬楼梯 (动态规划)
- [LeetCode] 70.爬楼梯
- 【LeetCode-面试算法经典-Java实现】【073-Climbing Stairs(爬楼梯)】
- [LeetCode] Min Cost Climbing Stairs 爬楼梯的最小损失
- Leetcode 746. Min Cost Climbing Stairs 最小成本爬楼梯 (动态规划)
- leetcode 70. Climbing Stairs QuestionEditorial
- LeetCode-70. Climbing Stairs
- LeetCode 70. Climbing Stairs
- leetcode-爬楼梯(动态规划)