Question: Python issue, want to pass the following two variables in as linked lists and then call the addNumberFunction, how would i convert the two following

Python issue, want to pass the following two variables in as linked lists and then call the addNumberFunction, how would i convert the two following to linked lists and then assign

class ListNode(object): def __init__(self, val=0, next=None): self.val = val self.next = next class Solution(object): def addTwoNumbers(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ carry = 0 root = n = ListNode(0) while l1 or l2 or carry: v1 = v2 = 0 if l1: v1 = l1.val l1 = l1.next if l2: v2 = l2.val l2 = l2.next carry, val = divmod(v1+v2+carry, 10) n.next = ListNode(val) n = n.next return root.next l1 = [2,4,3] //Change to linked list l2 = [5,6,4]

addTwoNumbers(self,l1, l2)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!