File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
lcof2/剑指 Offer II 091. 粉刷房子 Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,23 @@ impl Solution {
156
156
}
157
157
```
158
158
159
+ #### Swift
160
+
161
+ ``` swift
162
+ class Solution {
163
+ func minCost (_ costs : [[Int ]]) -> Int {
164
+ var r = 0 , g = 0 , b = 0
165
+ for cost in costs {
166
+ let _r = r, _g = g, _b = b
167
+ r = min (_g, _b) + cost[0 ]
168
+ g = min (_r, _b) + cost[1 ]
169
+ b = min (_r, _g) + cost[2 ]
170
+ }
171
+ return min (r, min (g, b))
172
+ }
173
+ }
174
+ ```
175
+
159
176
<!-- tabs: end -->
160
177
161
178
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func minCost( _ costs: [ [ Int ] ] ) -> Int {
3
+ var r = 0 , g = 0 , b = 0
4
+ for cost in costs {
5
+ let _r = r, _g = g, _b = b
6
+ r = min ( _g, _b) + cost[ 0 ]
7
+ g = min ( _r, _b) + cost[ 1 ]
8
+ b = min ( _r, _g) + cost[ 2 ]
9
+ }
10
+ return min ( r, min ( g, b) )
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments