宿舍 2019-12-27
java
public class Solution { public int Add(int num1,int num2) { while (num2!=0) { int temp = num1^num2; num2 = (num1&num2)<<1; num1 = temp; } return num1; } }
python
class Solution: def Add(self, num1, num2): # write code here while num2!=0: sum_ = num1 ^ num2 carry = (num1 & num2)<<1 num1=sum_%0x100000000 num2=carry%0x100000000 if num1<=0x7FFFFFFF: return num1 else: return num1 |(~0x100000000+1)