Clean python code


  • 2
    class Solution(object):
        def add(self, a, b):
            for _ in xrange(32):
                a, b = a ^ b, (a & b) << 1
            return a
    
        def getSum(self, a, b):
            s = self.add(a, b) & 0xFFFFFFFF
    
            # if sum is negative, we should translate two's complement to
            # the true form
            if s & 0x80000000:
                return -self.add(~(s & 0x7FFFFFFF) & 0x7FFFFFFF, 1)
    
            return s
    

  • 0
    C

    Operator - is used


  • 0

    Here - is not an operator, what do you think?


Log in to reply
 

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