mirror of https://github.com/doocs/leetcode.git
feat: add swift implementation to lcof problem: No.65 (#2960)
This commit is contained in:
parent
a9bd8a4dcc
commit
9a16d7b5ef
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue