Created
June 8, 2021 06:29
-
-
Save vrat28/b12f0007b701e285a77f58382077048b to your computer and use it in GitHub Desktop.
Min cost climbing stairs (Swift| LC 746)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
func minCostClimbingStairs(_ cost: [Int]) -> Int { | |
var dp = [Int](repeating:0, count: cost.count+1) | |
for i in 2..<dp.count{ | |
let oneStepCost = dp[i - 1] + cost[i - 1] | |
let twoStepCost = dp[i - 2] + cost[i - 2] | |
dp[i] = min(oneStepCost, twoStepCost) | |
} | |
return dp[cost.count] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment