fast solution with ^ & << (not bit-by-bit)


  • 0
    M

    JavaScript sample

    var getSum = function(a, b) {
        var c;
        while ((c = a & b) != 0) {
            a = a ^ b;
            b = c << 1;
        }
        return a ^ b;
    };
    

Log in to reply
 

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