We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 67559a2 commit ec52000Copy full SHA for ec52000
solution/0700-0799/0746.Min Cost Climbing Stairs/Solution2.rs
@@ -1,11 +1,10 @@
1
impl Solution {
2
pub fn min_cost_climbing_stairs(cost: Vec<i32>) -> i32 {
3
- let (mut f, mut g) = (0, 0);
4
- for i in 2..=cost.len() {
5
- let gg = std::cmp::min(f + cost[i - 2], g + cost[i - 1]);
6
- f = g;
7
- g = gg;
+ let n = cost.len();
+ let mut f = vec![0; n + 1];
+ for i in 2..=n {
+ f[i] = std::cmp::min(f[i - 2] + cost[i - 2], f[i - 1] + cost[i - 1]);
8
}
9
- g
+ f[n]
10
11
0 commit comments