feat: add swift implementation to lcof problem: No.65 (#2960)

This commit is contained in:
Lanre Adedara 2024-05-30 10:12:07 +01:00 committed by GitHub
parent a9bd8a4dcc
commit 9a16d7b5ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View File

@ -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
}
}
```
<!-- tabs:end -->
<!-- solution:end -->

View File

@ -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
}
}