剑指offer47 不用加减乘除做加法

自己写的

class Solution {
public:
    int Add(int num1, int num2)
    {
        int a = num1 ^ num2;
        int b = (num1 & num2) << 1;
        while(b){
            int c = a ^ b;
            int d = (a & b) << 1;
            a = c;
            b = d;
        }
        return a;
    }
};

注意:做位运算的与是&,不是&&

原文地址:https://www.cnblogs.com/ymjyqsx/p/7510707.html