File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
lcof2/剑指 Offer II 088. 爬楼梯的最少成本 Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -220,6 +220,23 @@ function minCostClimbingStairs(cost: number[]): number {
220
220
}
221
221
```
222
222
223
+ #### Swift
224
+
225
+ ``` swift
226
+ class Solution {
227
+ func minCostClimbingStairs (_ cost : [Int ]) -> Int {
228
+ var a = 0
229
+ var b = 0
230
+ for i in 1 ..< cost.count {
231
+ let c = min (a + cost[i - 1 ], b + cost[i])
232
+ a = b
233
+ b = c
234
+ }
235
+ return b
236
+ }
237
+ }
238
+ ```
239
+
223
240
<!-- tabs: end -->
224
241
225
242
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func minCostClimbingStairs( _ cost: [ Int ] ) -> Int {
3
+ var a = 0
4
+ var b = 0
5
+ for i in 1 ..< cost. count {
6
+ let c = min ( a + cost[ i - 1 ] , b + cost[ i] )
7
+ a = b
8
+ b = c
9
+ }
10
+ return b
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments