Skip to content

Commit ec52000

Browse files
authored
Update Solution2.rs
1 parent 67559a2 commit ec52000

File tree

1 file changed

+5
-6
lines changed
  • solution/0700-0799/0746.Min Cost Climbing Stairs

1 file changed

+5
-6
lines changed
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
impl Solution {
22
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;
3+
let n = cost.len();
4+
let mut f = vec![0; n + 1];
5+
for i in 2..=n {
6+
f[i] = std::cmp::min(f[i - 2] + cost[i - 2], f[i - 1] + cost[i - 1]);
87
}
9-
g
8+
f[n]
109
}
1110
}

0 commit comments

Comments
 (0)