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

This commit is contained in:
nuomi1
2023-09-24 22:50:09 +08:00
committed by GitHub
parent ff8e7ceec5
commit 72f243eec3
3 changed files with 80 additions and 52 deletions

View File

@@ -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]