Skip to content

Commit be711f2

Browse files
committed
747
1 parent fa58696 commit be711f2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

747/main.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
func min(a, b int) int {
2+
if a < b {
3+
return a
4+
}
5+
return b
6+
}
7+
8+
func minCostClimbingStairs(cost []int) int {
9+
if len(cost) <= 1 {
10+
return 0
11+
}
12+
dp := make([]int, len(cost))
13+
dp[0], dp[1] = cost[0], cost[1]
14+
for i := 2; i < len(cost); i++ {
15+
dp[i] = min(dp[i-1], dp[i-2]) + cost[i]
16+
}
17+
return min(dp[len(cost)-1], dp[len(cost)-2])
18+
}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
- [738 Monotone Increasing Digits](./738)
199199
- [739 Daily Temperatures](./739)
200200
- [740 Delete and Earn](./740)
201+
- [747 Min Cost Climbing Stairs](./747)
201202
- [748 Largest Number At Least Twice of Others](./748)
202203

203204
*Q: What is `LZS`? It almost appears inside all files (like js, cpp)?*

0 commit comments

Comments
 (0)