We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
假设你正在爬楼梯。需要 n 阶你才能到达楼顶。
n
每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
1
2
Input: 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps
Input: 3 Output: 3 Explanation: There are three ways to climb to the top. 1. 1 step + 1 step + 1 step 2. 1 step + 2 steps 3. 2 steps + 1 step
The text was updated successfully, but these errors were encountered:
/** * @param {number} n * @return {number} */ var climbStairs = function(n) { const dp = new Array(n + 1); for (let i = 0; i <= n; i++) { if (i < 2) { dp[i] = 1; } else { dp[i] = dp[i - 1] + dp[i - 2]; } } return dp[n]; };
function climbStairs(n: number): number { const dp: number[] = new Array(n + 1); for (let i = 0; i <= n; i++) { if (i < 2) { dp[i] = 1; } else { dp[i] = dp[i - 1] + dp[i - 2]; } } return dp[n]; }
Sorry, something went wrong.
No branches or pull requests
70. Climbing Stairs
假设你正在爬楼梯。需要
n
阶你才能到达楼顶。每次你可以爬
1
或2
个台阶。你有多少种不同的方法可以爬到楼顶呢?Example 1
Example 2
Note
n
是一个正整数The text was updated successfully, but these errors were encountered: