From dd84506695c57dda74fd142bb1d0a58473dd19c6 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Thu, 30 May 2024 08:02:39 +0100 Subject: [PATCH] Swift implementation for LCOF 65 --- .../README.md" | 17 +++++++++++++++++ .../Solution.swift" | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 "lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/Solution.swift" diff --git "a/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" index 8e5ac6922ce09..4fedd16b0cc36 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/README.md" @@ -159,6 +159,23 @@ public class Solution { } ``` +#### Swift + +```swift +class Solution { + func add(_ a: Int, _ b: Int) -> Int { + var a = a + var b = b + while b != 0 { + let c = (a & b) << 1 + a ^= b + b = c + } + return a + } +} +``` + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/Solution.swift" "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/Solution.swift" new file mode 100644 index 0000000000000..61ca8fd77cd45 --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23065. \344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/Solution.swift" @@ -0,0 +1,12 @@ +class Solution { + func add(_ a: Int, _ b: Int) -> Int { + var a = a + var b = b + while b != 0 { + let c = (a & b) << 1 + a ^= b + b = c + } + return a + } +} \ No newline at end of file