Sum of Two Integers (C)


  • 0
    P

    '''

    int getSum(int a, int b) {
    int sum=0, carry=0;
    long ln=0;
    sum = a^b;
    carry = (a&b)<<1;
    while(carry != 0){
    a = sum;
    b = carry;
    sum = a^b;
    carry = (a&b)<<1;
    }
    ln = ln|sum;
    return ln;
    }
    '''


  • 0
    P
    int getSum(int a, int b) {
        int sum=0, carry=0;
        long ln=0;
        sum = a^b;
        carry = (a&b)<<1;
        while(carry != 0){
            a = sum;
            b = carry;
            sum = a^b;
            carry = (a&b)<<1;
        }
        ln = ln|sum;
        return ln;
    }

Log in to reply
 

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