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.
def addTwoInt(a, b):
# python的问题,需要加这段判断
if b == -1 * a:
return 0
while b != 0:
c = a ^ b
b = (a & b) << 1
a = c
return a