diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/README.md" index bb55fa65ac8e7..7d0858ade6519 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/README.md" @@ -249,6 +249,40 @@ public class Solution { } ``` +#### Swift + +```swift +class Solution { + func minCut(_ s: String) -> Int { + let n = s.count + let sArray = Array(s) + + var g = Array(repeating: Array(repeating: true, count: n), count: n) + + for i in stride(from: n - 1, through: 0, by: -1) { + for j in i + 1.. 0 ? 1 + f[j - 1] : 0) + } + } + } + + return f[n - 1] + } +} +``` + diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/Solution.swift" "b/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/Solution.swift" new file mode 100644 index 0000000000000..94f93ea9befa0 --- /dev/null +++ "b/lcof2/\345\211\221\346\214\207 Offer II 094. \346\234\200\345\260\221\345\233\236\346\226\207\345\210\206\345\211\262/Solution.swift" @@ -0,0 +1,29 @@ +class Solution { + func minCut(_ s: String) -> Int { + let n = s.count + let sArray = Array(s) + + var g = Array(repeating: Array(repeating: true, count: n), count: n) + + for i in stride(from: n - 1, through: 0, by: -1) { + for j in i + 1.. 0 ? 1 + f[j - 1] : 0) + } + } + } + + return f[n - 1] + } +} \ No newline at end of file