Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
PENDING, THIS IS NOT THE SOLUTION!!!
Example:
Given a = 1 and b = 2, return 3.
class Solution {
func getSum(a: Int, _ b: Int) -> Int {
var c = a ^ b
var d = a & b
if (d != 0 & c) {
d = d << 1
//c = c ^ d
//d = d & c
getSum(c, d)
}
return c
}
}```
网友评论