feat(Swift): update min_cost_climbing_stairs_dp and hash_map_open_addressing (#792)

This commit is contained in:
nuomi1
2023-09-24 09:50:09 -05:00
committed by GitHub
parent ff8e7ceec5
commit 72f243eec3
3 changed files with 80 additions and 52 deletions
@@ -13,8 +13,8 @@ func minCostClimbingStairsDP(cost: [Int]) -> Int {
// 初始化 dp 表,用于存储子问题的解
var dp = Array(repeating: 0, count: n + 1)
// 初始状态:预设最小子问题的解
dp[1] = 1
dp[2] = 2
dp[1] = cost[1]
dp[2] = cost[2]
// 状态转移:从较小子问题逐步求解较大子问题
for i in stride(from: 3, through: n, by: 1) {
dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]