A 3-lines python solution

  • 2
    class Solution(object):
        def getSum(self, a, b):
            :type a: int
            :type b: int
            :rtype: int
            for _ in xrange(32):
                a, b = a^b, (a&b)<<1
            return a if a & 0x80000000 else a & 0xffffffff

Log in to reply

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