mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
18 lines
340 B
Python
18 lines
340 B
Python
def get_sum(self, a: int, b: int) -> int:
|
|
|
|
if a == -b:
|
|
return 0
|
|
|
|
if abs(a) > abs(b):
|
|
a, b = b, a
|
|
|
|
if a < 0:
|
|
return - get_sum(-a, -b)
|
|
|
|
while b:
|
|
|
|
c = a & b
|
|
a, b = a ^ b, c << 1
|
|
|
|
return a
|