Python solution using introspection


  • 0
    K
    class Solution(object):
    def getSum(self, a, b):
        """
        :type a: int
        :type b: int
        :rtype: int
        """
        return int.__add__(a,b)
    

    This might be violating the spirit of the question... or maybe not. :)

    It seems like it's intended just to see what you'd come up with.


  • 0
    This post is deleted!

  • 0

    Nice. Two variations:

    class Solution(object):
        def getSum(self, a, b):
            return a.__add__(b)
    
    class Solution(object):
        getSum = staticmethod(int.__add__)
    

    I'm interested in other working "cheating" solutions as well. I myself came up with this one:

    class Solution(object):
        def getSum(self, *a):
            return sum(a)

  • 0
    J

    @StefanPochmann:

    class Solution(object):
        def getSum(self, a, b):
            return operator.add(a, b)
    

    In the spirit...


Log in to reply
 

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