C solution.


  • 0
    N
    int getSum(int a, int b) {
        int sum=0,c;
        sum=a|b;
        c=a&b;
        while(c!=0){
          a=sum^c;
          b=c<<1;
          sum=a|b;
          c=a&b;
        }
        return sum;
    }
    

Log in to reply
 

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