美文网首页
Swift算法1-Sum of Two Integers--PE

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

作者: 四毛哥掉落的鳞片 | 来源:发表于2016-07-07 13:28 被阅读0次

    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--PE

          本文链接:https://www.haomeiwen.com/subject/nflljttx.html