Skip to content

Commit

Permalink
Create: 746-Min-Cost-Climbing-Stairs.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Ykhan799 authored Aug 31, 2022
1 parent b891412 commit 088d463
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions swift/746-Min-Cost-Climbing-Stairs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution {
func minCostClimbingStairs(_ cost: [Int]) -> Int {
var stepsCost = cost
for i in stride(from: cost.count - 3, through: 0, by: -1) {
stepsCost[i] += min(stepsCost[i + 1], stepsCost[i + 2])
}
return min(stepsCost[0], stepsCost[1])
}
}

0 comments on commit 088d463

Please sign in to comment.