371. Sum of Two Integers

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

Example:
Given a = 1 and b = 2, return 3.

此题讲解全部都在bit manipulation里面:

public class Solution {

    public int getSum(int a, int b) {

        if(b==0) return a;

        return getSum(a^b,(a&b)<<1);

    }

}

原文地址:https://www.cnblogs.com/codeskiller/p/6358613.html