mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
23 lines
405 B
Python
23 lines
405 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
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
|