For our last problem, we’re going to pretend that each node in a linked list holds the digit of a number. The tail node holds the most significant digit and the head node holds the least significant digit.
# 2 -> 4 -> 1 # represents the number 142 # 7 -> 1 # represents the number 17
Given two of these linked lists, write a function that returns the sum of the two numbers as a new linked list.
# 2 -> 4 -> 1 # plus # 7 -> 1 # returns # 9 -> 5 -> 1
- write a function:
add_two()takes two arguments, each an instance of
- return an instance of
LinkedListwhich contains the sum of the input linked lists.
Solve this problem and pass the tests. If you need help, check out the hint!