2235. Add Two Integers
On This Page
class Solution:
def sum(self, num1: int, num2: int) -> int:
num1, num2 = num1 & 0xFFFFFFFF, num2 & 0xFFFFFFFF
while num2:
carry = ((num1 & num2) << 1) & 0xFFFFFFFF
num1, num2 = num1 ^ num2, carry
return num1 if num1 < 0x80000000 else ~(num1 ^ 0xFFFFFFFF)