Skip to content

Commit 7ed9339

Browse files
committed
solve problem
1 parent c99eade commit 7ed9339

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
// Time O(log n)
3+
// Space O(1)
4+
func getSum(_ a: Int, _ b: Int) -> Int {
5+
var a = a
6+
var b = b
7+
8+
while b != 0 {
9+
var sum = a ^ b
10+
var carry = (a & b) << 1
11+
a = sum
12+
b = carry
13+
}
14+
15+
return a
16+
}
17+
}
18+

0 commit comments

Comments
 (0)