Bit manipulation solution


  • 0
    I
    public int getSum(int x, int y) {
            int a = x ^ y;
            int c = x & y;
            while (true){
                if((a ^ (c << 1)) == a){
                    break;
                }
                int temp = a;
                a = (a ^ (c << 1));
                c = temp & (c << 1);
            }
            return a;
        }

Log in to reply
 

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