Swift算法1-Sum of Two Integers--PENDING

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

你可能感兴趣的:(Swift算法1-Sum of Two Integers--PENDING)