剑指offer65 (Leetcode 371) 两整数之和解法一:基于递归和二进制异或的方法class Solution {public:int getSum(int a, int b) { //假设a=3,b=5int sum, c;sum = a ^ b; //3^5=0000 0011 ^ 0000 0101 = 0000 0110c = ((unsigned int)(a & b)) << 1; //3&5=0000 0011 & 0000 0101 = 0000 0001 再左移一位为0000 0010if (c != 0) {return getSum(sum, c);}return sum;}};解法二:基于迭代和二进制异或的方法class Solution2 {public:int getSum(int a, int b) {while (b != 0) {int c = a & b;a = a ^ b;b = (unsigned int)c << 1;}return a;}};