给出两个整数a和b, 求他们的和, 但不能使用+等数学运算符
</pre><pre code_snippet_id="1869488" snippet_file_name="blog_20160906_1_5558485" name="code" class="cpp">分析:用位操作异或和与来模拟进位
</pre><pre code_snippet_id="1869488" snippet_file_name="blog_20160906_2_7793740" name="code" class="cpp">class Solution {
public:
/*
* @param a: The first integer
* @param b: The second integer
* @return: The sum of a and b
*/
int aplusb(int a, int b) {
// write your code here, try to do it without arithmetic operators.
if(a==0)return b;
if(b==0)return a;
int x1 = a^b;
int x2 = (a&b)<<1;
return aplusb(x1,x2);
}
};