# -*- 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
线上测试的话超时,但是逻辑是没问题的
# -*- 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
线上测试的话超时,但是逻辑是没问题的