Sum of Two Integers

Solution Code
class Solution:
    def getSum(self, a: int, b: int) -> int:
        mask = 0xFFFFFFFF
        while b != 0:
            a, b = (a ^ b) & mask, ((a & b) << 1) & mask
        
        max_int = 0x7FFFFFFF
        return a if a <= max_int else ~(a ^ mask)
Video GuideLeetcode Daily

Time Complexity

O(1)

Space Complexity

O(1)