leetcode刷题记录2

介绍

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.

思路

。。。太简单了啊,利用python内置的一些有求和功能的函数来代替+号不就行了,比如列表的sum函数

代码

1
2
3
4
5
6
7
8
class Solution(object):
def getSum(self, a, b):
"""
:type a: int
:type b: int
:rtype: int
"""
return sum([a,b])