Leetcode: 371. Sum of Two Integers

这一题要用到|,&,<<等运算,完全参考https://discuss.leetcode.com/topic/49764/0ms-ac-java-solution/2算是当作学习了

public class TwoSumbin {
    public int getSum(int a, int b) {
        if (b == 0) {// 没有进为的时候完成运算
            return a;
        }
        int sum, carry;
        sum = a ^ b;// 完成第一步加发的运算
        carry = (a & b) << 1;// 完成第二步进位并且左移运算
        return getSum(sum, carry);//
    }

}
原文地址:https://www.cnblogs.com/Michael2397/p/8028058.html