Simple 0ms C routine without Carry

  • 0

    int getSum(int a, int b) {

         return (a^b)|((a&b)<<1); 
                         //this always works unless the addition (read OR) of the two halves involves yet another carry,                                     //hence the next step of recursion 
    else return(getSum((a^b),((a&b)<<1)));


Log in to reply

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