Skip to content

Commit 9a16d7b

Browse files
authored
feat: add swift implementation to lcof problem: No.65 (doocs#2960)
1 parent a9bd8a4 commit 9a16d7b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lcof/面试题65. 不用加减乘除做加法/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,23 @@ public class Solution {
159159
}
160160
```
161161

162+
#### Swift
163+
164+
```swift
165+
class Solution {
166+
func add(_ a: Int, _ b: Int) -> Int {
167+
var a = a
168+
var b = b
169+
while b != 0 {
170+
let c = (a & b) << 1
171+
a ^= b
172+
b = c
173+
}
174+
return a
175+
}
176+
}
177+
```
178+
162179
<!-- tabs:end -->
163180

164181
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
func add(_ a: Int, _ b: Int) -> Int {
3+
var a = a
4+
var b = b
5+
while b != 0 {
6+
let c = (a & b) << 1
7+
a ^= b
8+
b = c
9+
}
10+
return a
11+
}
12+
}

0 commit comments

Comments
 (0)