Straightforward with C++


  • 0
    A
    class Solution {
    public:
        int i = 0x1;
        int xor_val = 0;
        int and_val = 0;
        int getSum(int a, int b) {
            xor_val  = a ^ b;
            and_val  = a & b;
            a = xor_val;
            b = and_val << 1;
            if (b == 0)
                return a;
            else
                return getSum(a,b);
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.