You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: leetcode/3601-3700/3693.Climbing-Stairs-II/README.md
+46-12Lines changed: 46 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,62 @@
1
1
# [3693.Climbing Stairs II][title]
2
2
3
-
> [!WARNING|style:flat]
4
-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5
-
6
3
## Description
4
+
You are climbing a staircase with `n + 1` steps, numbered from 0 to `n`.
5
+
6
+
You are also given a **1-indexed** integer array `costs` of length `n`, where `costs[i]` is the cost of step `i`.
7
+
8
+
From step `i`, you can jump **only** to step `i + 1`, `i + 2`, or `i + 3`. The cost of jumping from step `i` to step `j` is defined as: `costs[j] + (j - i)^2`
9
+
10
+
You start from step 0 with `cost = 0`.
11
+
12
+
Return the **minimum** total cost to reach step `n`.
7
13
8
14
**Example 1:**
9
15
10
16
```
11
-
Input: a = "11", b = "1"
12
-
Output: "100"
17
+
Input: n = 4, costs = [1,2,3,4]
18
+
19
+
Output: 13
20
+
21
+
Explanation:
22
+
23
+
One optimal path is 0 → 1 → 2 → 4
24
+
25
+
Jump Cost Calculation Cost
26
+
0 → 1 costs[1] + (1 - 0)2 = 1 + 1 2
27
+
1 → 2 costs[2] + (2 - 1)2 = 2 + 1 3
28
+
2 → 4 costs[4] + (4 - 2)2 = 4 + 4 8
29
+
Thus, the minimum total cost is 2 + 3 + 8 = 13
13
30
```
14
31
15
-
## 题意
16
-
> ...
32
+
**Example 2:**
17
33
18
-
## 题解
34
+
```
35
+
Input: n = 4, costs = [5,1,6,2]
19
36
20
-
### 思路1
21
-
> ...
22
-
Climbing Stairs II
23
-
```go
37
+
Output: 11
38
+
39
+
Explanation:
40
+
41
+
One optimal path is 0 → 2 → 4
42
+
43
+
Jump Cost Calculation Cost
44
+
0 → 2 costs[2] + (2 - 0)2 = 1 + 4 5
45
+
2 → 4 costs[4] + (4 - 2)2 = 2 + 4 6
46
+
Thus, the minimum total cost is 5 + 6 = 11
24
47
```
25
48
49
+
**Example 3:**
50
+
51
+
```
52
+
Input: n = 3, costs = [9,8,3]
53
+
54
+
Output: 12
55
+
56
+
Explanation:
57
+
58
+
The optimal path is 0 → 3 with total cost = costs[3] + (3 - 0)2 = 3 + 9 = 12
0 commit comments