Java Solution using Bit Manipulation


  • 0
    E
    public class Solution {
        public int getSum(int a, int b) {
            int c = a ^ b;
            int d = a & b;
            while(d!=0){
                int e = c;
                c ^= (d<<1);
                d = e & (d<<1);
            }
            return c;
        }
    }

Log in to reply
 

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