首页 > 其他 > 详细

Leetcode - 371. Sum of Two Integers

时间:2018-10-24 19:16:42      阅读:146      评论:0      收藏:0      [点我收藏+]

题设:

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

解题思路:

使用加法器

代码:

class Solution:
    def getSum(self, num1, num2):
        if (num2 == 0):
            return num1
        sum = num1 ^ num2
        carry = (num1 & num2) << 1
        return self.getSum(sum,carry)

结果:

python本地运行:通过

run code运行:通过,运行时间32ms

submit结果:不通过,报“超出内存限制”

Leetcode - 371. Sum of Two Integers

原文:https://www.cnblogs.com/kaezah/p/9844930.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!