[LeetCode] Climbing Stairs
2023-09-11 14:17:25 时间
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?
Dynamic Programming
Have you met this question in a real interview?
Yes
No
思路:动态规划+斐波那契数列,最简单的dp
class Solution { public: int climbStairs(int n) { vector<int> f(n+1, 0); f[0] = 1; f[1] = 1; for(int i = 2; i <= n; i++) { f[i] = f[i-1] + f[i-2]; } return f[n]; } };
相关文章
- Java实现 LeetCode 791 自定义字符串排序(桶排序)
- Java实现 LeetCode 781 森林中的兔子(分析题)
- Java实现 LeetCode 780 到达终点(逻辑题)
- Java实现 LeetCode 561 数组拆分 I(通过排序算法改写PS:难搞)
- Java实现 LeetCode 437 路径总和 III(三)
- Java实现 LeetCode 300 最长上升子序列
- Java实现 LeetCode 179 最大数
- Java实现LeetCode_0027_RemoveElement
- LeetCode(26): 删除排序数组中的重复项
- (LeetCode 203)Remove Linked List Elements
- LeetCode(100):相同的树
- LeetCode(38): 报数
- Leetcode学习计划之动态规划入门day20(322,518)
- Leetcode 四数相加 II
- leetcode 217. Contains Duplicate
- 【Leetcode刷题Python】77. 组合