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 @@ -235,6 +235,23 @@ function minCostClimbingStairs(cost: number[]): number {
235
235
}
236
236
```
237
237
238
+ #### Swift
239
+
240
+ ``` swift
241
+ class Solution {
242
+ func minCostClimbingStairs (_ cost : [Int ]) -> Int {
243
+ var a = 0
244
+ var b = 0
245
+ for i in 1 ..< cost.count {
246
+ let c = min (a + cost[i - 1 ], b + cost[i])
247
+ a = b
248
+ b = c
249
+ }
250
+ return b
251
+ }
252
+ }
253
+ ```
254
+
238
255
<!-- tabs: end -->
239
256
240
257
<!-- 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