0

Write a function that add two numbers A and B.

 class Solution:
    """
    @param a: An integer
    @param b: An integer
    @return: The sum of a and b 
    """
    def aplusb(self, a, b):
        # write your code here

        while True:
            a, b = a^b, (a&b)<<1
            if a==0 or b == 0:
                return a or b

Hint Your code ran too much time than we expected. Check your time complexity. Time limit exceeded usually caused by infinite loop if your time complexity is the best.

carl
  • 1
  • 1
    What exactly is your question? – Harly Hallikas Feb 18 '19 at 12:15
  • 1
    Possible duplicate of https://stackoverflow.com/q/30696484/7351855 – Matej Feb 18 '19 at 12:16
  • Possible duplication of [https://stackoverflow.com/questions/38557464/sum-of-two-integers-without-using-operator-in-python](https://stackoverflow.com/questions/38557464/sum-of-two-integers-without-using-operator-in-python) – DavidDr90 Feb 18 '19 at 14:33
  • Possible duplicate of [Sum of Two Integers without using "+" operator in python](https://stackoverflow.com/questions/38557464/sum-of-two-integers-without-using-operator-in-python) – DavidDr90 Feb 18 '19 at 14:33

0 Answers0