A simple of java solution with 0ms.Add a example of Picture.


  • 4
    L

    public int getSum(int a, int b) {

            int sum=a^b;
            int carry=a&b;
            int tmp=0;	        
            while(carry!=0){
                carry=carry<<1;
                tmp=sum;
                sum=carry^sum;
                carry=carry&tmp;
            }	       
            return sum;
    }

  • 0
    L

    I make a simple example to explain this algorithm.^^.because this Photo is to large,you can right click on the photo to choose item of the new tab to see the picture or save as to desktop to see it.->->
    a example to explain this problem


  • 0
    B

    This really help, thank you!


Log in to reply
 

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