From 81870328666ce313e3d01f87e5f9b51c2bb9f8fb Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Mon, 11 Nov 2024 08:40:52 +0100 Subject: [PATCH] feat: add swift implementation to lcp problem: No.06 --- .../README.md" | 14 ++++++++++++++ .../Solution.swift" | 9 +++++++++ 2 files changed, 23 insertions(+) create mode 100644 "lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.swift" diff --git "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" index a13eeebc8f399..fd1f297a5456f 100644 --- "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" +++ "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" @@ -154,6 +154,20 @@ int minCount(int* coins, int coinsSize) { } ``` +#### Swift + +```swift +class Solution { + func minCount(_ coins: [Int]) -> Int { + var ans = 0 + for x in coins { + ans += (x + 1) >> 1 + } + return ans + } +} +``` + diff --git "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.swift" "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.swift" new file mode 100644 index 0000000000000..9b88a97b003b4 --- /dev/null +++ "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.swift" @@ -0,0 +1,9 @@ +class Solution { + func minCount(_ coins: [Int]) -> Int { + var ans = 0 + for x in coins { + ans += (x + 1) >> 1 + } + return ans + } +} \ No newline at end of file