diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md index c2c73715..0006f7ac 100644 --- a/problems/0746.使用最小花费爬楼梯.md +++ b/problems/0746.使用最小花费爬楼梯.md @@ -288,6 +288,24 @@ function minCostClimbingStairs(cost: number[]): number { }; ``` +### Rust + +```Rust +use std::cmp::min; +impl Solution { + pub fn min_cost_climbing_stairs(cost: Vec) -> i32 { + let len = cost.len(); + let mut dp = vec![0; len]; + dp[0] = cost[0]; + dp[1] = cost[1]; + for i in 2..len { + dp[i] = min(dp[i-1], dp[i-2]) + cost[i]; + } + min(dp[len-1], dp[len-2]) + } +} +``` + ### C ```c