Solution for "Sum of Two Integers" using bitwise operators


  • 0
    C

    I thought of a simple solution for this problem using bitwise operators and not using + for doing actual addition as the question intends:

    class Solution(object):
        def getSum(self, a, b):
            """
            :type a: int
            :type b: int
            :rtype: int
            """
            return (a|b) + (a&b)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.