Introduction
在昨天的基础上,今天我们来看爬楼梯问题。 问题描述: You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 我们按照之前的方法思考这个问题: 首先我们需要
- 定义状态:爬到第 n 级台阶
- 写出转移方程:
- 初始化:
- 确定便利顺序:
def climbStairs(n):