python3 按位异或 按位与
不用加减乘除做加法
http://www.nowcoder.com/questionTerminal/59ac416b4b944300b617d4f7f111b215
# -*- coding:utf-8 -*-
class Solution:
def Add(self, num1, num2):
# write code here
while num2 != 0:
temp = num1 ^ num2 # 保存不进位加法值
num2 = (num1 & num2) << 1 # 保存进位值
num1 = temp
return num1
线上测试的话超时,但是逻辑是没问题的
