70. 爬楼梯

执行用时:0 ms, 在所有 Swift 提交中击败了100.00%的用户
内存消耗:13.5 MB, 在所有 Swift 提交中击败了45.13%的用户

题目链接:https://leetcode-cn.com/problems/climbing-stairs/

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
func climbStairs(_ n: Int) -> Int {
var dp = [Int].init(repeating: 0, count: n+1)
dp[0] = 1
dp[1] = 1
if n >= 2{
for i in 2 ... n {
dp[i] = dp[i-1] + dp[i-2]
}
}
return dp[n]
}
}

70. 爬楼梯
https://pisces34.github.io/2021/09/04/leetcode/70/
发布于
2021年9月4日
许可协议