//不使用运算符 + 和 - ,计算两整数 a 、b 之和。 
//
// 示例 1: 
//
// 输入: a = 1, b = 2
//输出: 3
// 
//
// 示例 2: 
//
// 输入: a = -2, b = 3
//输出: 1 
// Related Topics 位运算 
// 👍 379 👎 0

/*
* 371 两整数之和
* 2021-03-12 15:09:49
* @author oxygenbytes
*/ 
#include "leetcode.h" 
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public:
    int getSum(int a, int b) {
        if(!b) return a;
        // 每轮循环b最后一位都会多一个0,最多循环32轮
        int sum = a ^ b, carry = (unsigned int)(a & b) << 1;
        return getSum(sum, carry);
    }
};
//leetcode submit region end(Prohibit modification and deletion)