Skip to content

Commit f2bdf60

Browse files
committed
三刷70
1 parent d8dd87f commit f2bdf60

File tree

3 files changed

+70
-30
lines changed

3 files changed

+70
-30
lines changed

docs/0070-climbing-stairs.adoc

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
[#0070-climbing-stairs]
2-
= 70. Climbing Stairs
2+
= 70. 爬楼梯
33

4-
{leetcode}/problems/climbing-stairs/[LeetCode - Climbing Stairs^]
4+
https://leetcode.cn/problems/climbing-stairs/[LeetCode - 70. 爬楼梯^]
55

6-
You are climbing a stair case. It takes _n_ steps to reach to the top.
6+
假设你正在爬楼梯。需要 `n` 阶你才能到达楼顶。
77

8-
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
8+
每次你可以爬 `1``2` 个台阶。你有多少种不同的方法可以爬到楼顶呢?
99

10-
*Note:* Given _n_ will be a positive integer.
10+
*示例 1:*
1111

12-
*Example 1:*
12+
....
13+
输入:n = 2
14+
输出:2
15+
解释:有两种方法可以爬到楼顶。
16+
1. 1 阶 + 1 阶
17+
2. 2 阶
18+
....
1319

14-
[subs="verbatim,quotes,macros"]
15-
----
16-
*Input:* 2
17-
*Output:* 2
18-
*Explanation:* There are two ways to climb to the top.
19-
1. 1 step + 1 step
20-
2. 2 steps
21-
----
20+
*示例 2:*
2221

23-
*Example 2:*
22+
....
23+
输入:n = 3
24+
输出:3
25+
解释:有三种方法可以爬到楼顶。
26+
1. 1 阶 + 1 阶 + 1 阶
27+
2. 1 阶 + 2 阶
28+
3. 2 阶 + 1 阶
29+
....
30+
31+
*提示:*
32+
33+
* `+1 <= n <= 45+`
2434
25-
[subs="verbatim,quotes,macros"]
26-
----
27-
*Input:* 3
28-
*Output:* 3
29-
*Explanation:* There are three ways to climb to the top.
30-
1. 1 step + 1 step + 1 step
31-
2. 1 step + 2 steps
32-
3. 2 steps + 1 step
33-
----
3435
3536
== 思路分析
3637

@@ -79,13 +80,22 @@ include::{sourcedir}/_0070_ClimbingStairs.java[tag=answer]
7980
include::{sourcedir}/_0070_ClimbingStairs_2.java[tag=answer]
8081
----
8182
--
82-
====
83-
84-
== 参考资料
8583
86-
. https://leetcode.cn/problems/climbing-stairs/solutions/2361764/70-pa-lou-ti-dong-tai-gui-hua-qing-xi-tu-ruwa/?envType=study-plan-v2&envId=selected-coding-interview[70. 爬楼梯 - 动态规划,清晰图解^]
87-
. https://leetcode.cn/problems/climbing-stairs/solutions/286022/pa-lou-ti-by-leetcode-solution/?envType=study-plan-v2&envId=selected-coding-interview[70. 爬楼梯 - 官方题解^]
88-
. https://leetcode.cn/problems/climbing-stairs/solutions/2560716/jiao-ni-yi-bu-bu-si-kao-dong-tai-gui-hua-7zm1/?envType=study-plan-v2&envId=selected-coding-interview[70. 爬楼梯 - 教你一步步思考动态规划:从记忆化搜索到递推^]
84+
三刷::
85+
+
86+
--
87+
[{java_src_attr}]
88+
----
89+
include::{sourcedir}/_0070_ClimbingStairs_3.java[tag=answer]
90+
----
91+
--
92+
====
8993

9094

95+
== 参考资料
9196

97+
. https://leetcode.cn/problems/climbing-stairs/solutions/2560716/jiao-ni-yi-bu-bu-si-kao-dong-tai-gui-hua-7zm1/[70. 爬楼梯 - 教你一步步思考动态规划:从记忆化搜索到递推^]
98+
. https://leetcode.cn/problems/climbing-stairs/solutions/270926/cong-zhi-jue-si-wei-fen-xi-dong-tai-gui-hua-si-lu-/[70. 爬楼梯 - 「手画图解」详解爬楼梯问题 | 从递归,讲到动态规划^]
99+
. https://leetcode.cn/problems/climbing-stairs/solutions/854668/dai-ma-sui-xiang-lu-dong-tai-gui-hua-jin-y1hw/[70. 爬楼梯 - 「代码随想录」动态规划精讲!^]
100+
. https://leetcode.cn/problems/climbing-stairs/solutions/2361764/70-pa-lou-ti-dong-tai-gui-hua-qing-xi-tu-ruwa/[70. 爬楼梯 - 动态规划,清晰图解^]
101+
. https://leetcode.cn/problems/climbing-stairs/solutions/286022/pa-lou-ti-by-leetcode-solution/[70. 爬楼梯 - 官方题解^]

logbook/202503.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,11 @@ endif::[]
19541954
|{doc_base_url}/0072-edit-distance.adoc[题解]
19551955
|❌ 动态规划。计算 `dp[c][r]` 时,从相邻三个元素获取递推的含义还要好好思考一下,“增”、“删”和“改”的含义要理解清楚。
19561956

1957+
|{counter:codes2503}
1958+
|{leetcode_base_url}/climbing-stairs/[70. 爬楼梯^]
1959+
|{doc_base_url}/0070-climbing-stairs.adoc[题解]
1960+
|✅ 动态规划。也就是斐波那契数列,没想到这竟然是最简单的动态规划题目。
1961+
19571962
|===
19581963

19591964
截止目前,本轮练习一共完成 {codes2503} 道题。
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.diguage.algo.leetcode;
2+
3+
public class _0070_ClimbingStairs_3 {
4+
// tag::answer[]
5+
/**
6+
* @author D瓜哥 · https://www.diguage.com
7+
* @since 2025-11-21 23:18:37
8+
*/
9+
public int climbStairs(int n) {
10+
if (n == 1) {
11+
return 1;
12+
}
13+
if (n == 2) {
14+
return 2;
15+
}
16+
int a = 1, b = 2;
17+
for (int i = 3; i <= n; i++) {
18+
int sum = a + b;
19+
a = b;
20+
b = sum;
21+
}
22+
return b;
23+
}
24+
// end::answer[]
25+
}

0 commit comments

Comments
 (0)