From d0cbc741cd6f11a9fe069dc03522a148f99575f4 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Fri, 26 Apr 2024 08:42:36 +0100 Subject: [PATCH 1/2] Swift Implementation for LCCI 05.06 --- lcci/05.06.Convert Integer/README.md | 8 ++++++++ lcci/05.06.Convert Integer/README_EN.md | 8 ++++++++ lcci/05.06.Convert Integer/Solution.swift | 5 +++++ 3 files changed, 21 insertions(+) create mode 100644 lcci/05.06.Convert Integer/Solution.swift diff --git a/lcci/05.06.Convert Integer/README.md b/lcci/05.06.Convert Integer/README.md index 9c14eb779b788..dce788419aab4 100644 --- a/lcci/05.06.Convert Integer/README.md +++ b/lcci/05.06.Convert Integer/README.md @@ -91,6 +91,14 @@ impl Solution { } ``` +```swift +class Solution { + func convertInteger(_ A: Int, _ B: Int) -> Int { + return (A ^ B).nonzeroBitCount + } +} +``` + diff --git a/lcci/05.06.Convert Integer/README_EN.md b/lcci/05.06.Convert Integer/README_EN.md index b3f47402923d5..3494b81e0824f 100644 --- a/lcci/05.06.Convert Integer/README_EN.md +++ b/lcci/05.06.Convert Integer/README_EN.md @@ -108,6 +108,14 @@ impl Solution { } ``` +```swift +class Solution { + func convertInteger(_ A: Int, _ B: Int) -> Int { + return (A ^ B).nonzeroBitCount + } +} +``` + diff --git a/lcci/05.06.Convert Integer/Solution.swift b/lcci/05.06.Convert Integer/Solution.swift new file mode 100644 index 0000000000000..34f5e0a3a00e9 --- /dev/null +++ b/lcci/05.06.Convert Integer/Solution.swift @@ -0,0 +1,5 @@ +class Solution { + func convertInteger(_ A: Int, _ B: Int) -> Int { + return (A ^ B).nonzeroBitCount + } +} \ No newline at end of file From 80525e0b66938407734879e3bce58418d4a846b4 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Fri, 26 Apr 2024 09:18:33 +0100 Subject: [PATCH 2/2] code update --- lcci/05.06.Convert Integer/README.md | 2 +- lcci/05.06.Convert Integer/README_EN.md | 2 +- lcci/05.06.Convert Integer/Solution.swift | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lcci/05.06.Convert Integer/README.md b/lcci/05.06.Convert Integer/README.md index dce788419aab4..93ee5ccd0a072 100644 --- a/lcci/05.06.Convert Integer/README.md +++ b/lcci/05.06.Convert Integer/README.md @@ -94,7 +94,7 @@ impl Solution { ```swift class Solution { func convertInteger(_ A: Int, _ B: Int) -> Int { - return (A ^ B).nonzeroBitCount + return (Int32(A) ^ Int32(B)).nonzeroBitCount } } ``` diff --git a/lcci/05.06.Convert Integer/README_EN.md b/lcci/05.06.Convert Integer/README_EN.md index 3494b81e0824f..5a8c4995bba79 100644 --- a/lcci/05.06.Convert Integer/README_EN.md +++ b/lcci/05.06.Convert Integer/README_EN.md @@ -111,7 +111,7 @@ impl Solution { ```swift class Solution { func convertInteger(_ A: Int, _ B: Int) -> Int { - return (A ^ B).nonzeroBitCount + return (Int32(A) ^ Int32(B)).nonzeroBitCount } } ``` diff --git a/lcci/05.06.Convert Integer/Solution.swift b/lcci/05.06.Convert Integer/Solution.swift index 34f5e0a3a00e9..07a53a2db366e 100644 --- a/lcci/05.06.Convert Integer/Solution.swift +++ b/lcci/05.06.Convert Integer/Solution.swift @@ -1,5 +1,5 @@ class Solution { func convertInteger(_ A: Int, _ B: Int) -> Int { - return (A ^ B).nonzeroBitCount + return (Int32(A) ^ Int32(B)).nonzeroBitCount } -} \ No newline at end of file +}