C++ solution with bit operator


  • 0
    L
    int getSum(int a, int b) {
        int a_d = a & b;
        int o_r = a | b;
        while(a_d)
        {
            a = a_d << 1;
            b = a_d ^ o_r;
            a_d = a & b;
            o_r = a | b;
        }
        return a | b;
    }

Log in to reply
 

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