371_Sum_of_Two_Integers.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:leetcode 作者: qiyuangong 项目源码 文件源码
def getSum(self, a, b):
        """
        :type a: int
        :type b: int
        :rtype: int
        """
        # https://leetcode.com/discuss/111582/java-simple-easy-understand-solution-with-explanation
        # in Python this problem is much different because of the negative number
        # https://leetcode.com/discuss/111705/one-positive-one-negative-case-successful-for-python-rules
        import ctypes
        sum = 0
        carry = ctypes.c_int32(b)
        while carry.value != 0:
            sum = a ^ carry.value
            carry = ctypes.c_int32(a & carry.value)
            carry.value <<= 1
            a = sum
        return sum
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号