diff --git "a/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/README.md" "b/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/README.md" index 5caceb7fe92ad..47753dabb0320 100644 --- "a/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/README.md" +++ "b/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/README.md" @@ -200,6 +200,35 @@ function minimumOperations(leaves: string): number { } ``` +#### Swift + +```swift +class Solution { + func minimumOperations(_ leaves: String) -> Int { + let n = leaves.count + let inf = Int.max / 2 + var f = Array(repeating: [inf, inf, inf], count: n) + let leavesArray = Array(leaves) + + f[0][0] = leavesArray[0] == "r" ? 0 : 1 + + for i in 1.. diff --git "a/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/Solution.swift" "b/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/Solution.swift" new file mode 100644 index 0000000000000..18c6f753b5f39 --- /dev/null +++ "b/lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/Solution.swift" @@ -0,0 +1,24 @@ +class Solution { + func minimumOperations(_ leaves: String) -> Int { + let n = leaves.count + let inf = Int.max / 2 + var f = Array(repeating: [inf, inf, inf], count: n) + let leavesArray = Array(leaves) + + f[0][0] = leavesArray[0] == "r" ? 0 : 1 + + for i in 1..