Skip to content

Commit 088d463

Browse files
authored
Create: 746-Min-Cost-Climbing-Stairs.swift
1 parent b891412 commit 088d463

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution {
2+
func minCostClimbingStairs(_ cost: [Int]) -> Int {
3+
var stepsCost = cost
4+
for i in stride(from: cost.count - 3, through: 0, by: -1) {
5+
stepsCost[i] += min(stepsCost[i + 1], stepsCost[i + 2])
6+
}
7+
return min(stepsCost[0], stepsCost[1])
8+
}
9+
}

0 commit comments

Comments
 (0)