mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0070.爬楼梯完全背包版本.md
添加 pyhthon3 版本代码
This commit is contained in:
@ -147,6 +147,23 @@ class Solution {
|
|||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
|
||||||
|
```python3
|
||||||
|
class Solution:
|
||||||
|
def climbStairs(self, n: int) -> int:
|
||||||
|
dp = [0]*(n + 1)
|
||||||
|
dp[0] = 1
|
||||||
|
m = 2
|
||||||
|
# 遍历背包
|
||||||
|
for j in range(n + 1):
|
||||||
|
# 遍历物品
|
||||||
|
for step in range(1, m + 1):
|
||||||
|
if j >= step:
|
||||||
|
dp[j] += dp[j - step]
|
||||||
|
return dp[n]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user