From 1cacaaaa6d8ca35037d9f0f9f554416498768de9 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Wed, 13 Nov 2024 07:43:49 +0100 Subject: [PATCH 1/2] feat: add swift implementation to lcp problem: No.19 --- .../README.md" | 29 +++++++++++++++++++ .../Solution.swift" | 24 +++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 "lcp/LCP 19. \347\247\213\345\217\266\346\224\266\350\227\217\351\233\206/Solution.swift" 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..7ee805db7954f 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.. Date: Wed, 13 Nov 2024 06:54:39 +0000 Subject: [PATCH 2/2] style: format code and docs with prettier --- .../README.md" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 7ee805db7954f..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" @@ -209,9 +209,9 @@ class Solution { 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..