xautxuqiang

问题:

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

Example:
Given a = 1 and b = 2, return 3.

class Solution(object):
    def getSum(self, a, b):
        """
        :type a: int
        :type b: int
        :rtype: int
        """
        if(0 == b):
            return a
        sum1 = a^b
        carry = (a&b)<<1
        return Solution().getSum(sum1,carry)

if __name__ == \'__main__\':
        l = Solution().getSum(3,7)
        print l

 

分类:

技术点:

相关文章:

  • 2021-10-09
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2021-11-05
  • 2021-07-12
  • 2022-12-23
相关资源
相似解决方案