【Python】【难度:简单】Leetcode 面试题 17.01. 不用加号的加法

设计一个函数把两个数字相加。不得使用 + 或者其他算术运算符。

示例:

输入: a = 1, b = 1
输出: 2
 

提示:

a, b 均可能是负数或 0
结果不会溢出 32 位整数

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/add-without-plus-lcci
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

class Solution(object):
    def add(self, a, b):
        """
        :type a: int
        :type b: int
        :rtype: int
        """
        return sum([a,b])

执行结果:

通过

显示详情

执行用时 :20 ms, 在所有 Python 提交中击败了60.29%的用户

内存消耗 :12.6 MB, 在所有 Python 提交中击败了100.00%的用户

原创文章 105 获赞 0 访问量 1688

猜你喜欢

转载自blog.csdn.net/thomashhs12/article/details/105958377