My Java solution

  • 4
    public int getSum(int a, int b) {
        while ((a & b) != 0x00) {//check carry bit
            final int x = (a & b) << 1;//same bit has carry
            final int y = (a ^ b);     //different bit
            a = x;
            b = y;
        return a | b;

Log in to reply

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