756. Multiply Two Numbers

"""
Definition of ListNode
class ListNode(object):
    def __init__(self, val, next=None):
        self.val = val
        self.next = next
"""

class Solution:
    """
    @param l1: the first list
    @param l2: the second list
    @return: the product list of l1 and l2
    """
    def multiplyLists(self, l1, l2):
        # write your code here
        def decode(linkedList):
            digit = linkedList
            num = 0
            while digit:
                num *= 10
                num += digit.val
                digit = digit.next
            return num
        sumNum = decode(l1) * decode(l2)
        return sumNum

Last updated

Was this helpful?