File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,23 @@ public class Solution {
183
183
}
184
184
```
185
185
186
+ #### Swift
187
+
188
+ ``` swift
189
+ class Solution {
190
+ func cuttingRope (_ n : Int ) -> Int {
191
+ var f = [Int ](repeating : 0 , count : n + 1 )
192
+ f[1 ] = 1
193
+ for i in 2 ... n {
194
+ for j in 1 ..< i {
195
+ f[i] = max (f[i], max (f[i - j] * j, (i - j) * j))
196
+ }
197
+ }
198
+ return f[n]
199
+ }
200
+ }
201
+ ```
202
+
186
203
<!-- tabs: end -->
187
204
188
205
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func cuttingRope( _ n: Int ) -> Int {
3
+ var f = [ Int] ( repeating: 0 , count: n + 1 )
4
+ f [ 1 ] = 1
5
+ for i in 2 ... n {
6
+ for j in 1 ..< i {
7
+ f [ i] = max ( f [ i] , max ( f [ i - j] * j, ( i - j) * j) )
8
+ }
9
+ }
10
+ return f [ n]
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments