My 0ms Java Solution


  • 0
    F
    public class Solution {
        public int getSum(int a, int b) {
            int mask, res = 0, carry = 0;
            
            for(mask = 1; mask != 0; mask <<= 1, carry <<= 1) {
                res |= (a&mask)^(b&mask)^carry;
                carry = carry&a | carry&b | a&b&mask;
            }
            
            return res;
        }
    }
    

Log in to reply
 

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