My java Recursive solution


  • 0
    E
    public class Solution {
        public int getSum(int a, int b) {
            int xor = a ^ b;
            int carry = (a & b) << 1;
            int result = 0;
            if ((carry & xor) != 0) {
               result = getSum (xor, carry);
            }
            else {
                result = carry ^ xor ;
            }
            return result;
            
        }
    }
    

Log in to reply
 

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