From 83f3c4ede84c47387e64d05abfd686e8f53d3e8d Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Mon, 11 Nov 2024 09:41:57 +0100 Subject: [PATCH] feat: add swift implementation to lcp problem: No.06 (#3741) --- lcp/LCP 06. 拿硬币/README.md | 14 ++++++++++++++ lcp/LCP 06. 拿硬币/Solution.swift | 9 +++++++++ 2 files changed, 23 insertions(+) create mode 100644 lcp/LCP 06. 拿硬币/Solution.swift diff --git a/lcp/LCP 06. 拿硬币/README.md b/lcp/LCP 06. 拿硬币/README.md index a13eeebc8f..fd1f297a54 100644 --- a/lcp/LCP 06. 拿硬币/README.md +++ b/lcp/LCP 06. 拿硬币/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. 拿硬币/Solution.swift b/lcp/LCP 06. 拿硬币/Solution.swift new file mode 100644 index 0000000000..9b88a97b00 --- /dev/null +++ b/lcp/LCP 06. 拿硬币/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