Single line Python Solution using reduce

  • 0

    class Solution(object):
    def addStrings(self, num1, num2):
    ......... return str(reduce(lambda x, y: x*10 + ord(y)-48, num1, 0) + reduce(lambda x, y: x*10 + ord(y)-48, num2, 0))

  • 1

    @vnext999 Actually this is cheating because you're implicitly using the BigInt library of Python. You code is equivalent of writing return int(num1) + int(num2). Converting to integer by using reduce doesn't make it any less cheating :)

Log in to reply

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