OJ:lintcode 二进制求和

给定两个二进制字符串,返回他们的和(用二进制表示)。
您在真实的面试中是否遇到过这个题?
Yes
样例
a = 11
b = 1
返回 100

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(b==0){
            return a;
        }
        else{
            int x1=a^b;
            int x2=a&b;
            aplusb(x1,x2<<1);
        }
        
    }
};

你可能感兴趣的:(OJ:lintcode 二进制求和)