LeetCode--371--两整数之和

问题描述:

方法:

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

另:

 class Solution(object):
def getSum(self, a, b):
"""
:type a: int
:type b: int
:rtype: int
"""
no_carry_sum=a^b
carry_sum=(a&b)<<1 左移一位 3<<1 6 3 & 1 = 1进位
return sum([no_carry_sum,carry_sum])

2018-09-27 09:42:03

上一篇:elasticsearch中head插件中的定制增加用户名密码范例


下一篇:iOS - OC 面向对象语法