Add two linked lists
EasyLet's say you're given two linked lists that each represent a number.
For example, the linked list
(1) -> (3) -> (4) -> (7)
represents the number 1,347
.Write a function that adds the two input numbers represented by linked lists, and returns the sum represented by a linked list.
Note that the first node is the most significant digit, and the last node is the least significant digit.
For example, a function that's passed these inputs:
(1) -> (4) -> (7)(2) -> (3)
should return:
(1) -> (7) -> (0)
Try it first
Solution
8 Essential Linked Lists Coding Interview Problems
Master Linked Lists by trying the coding challenges below.
- 1.Insert NodeEasy
- 2.Remove NodeEasy
- 3.Find the MiddleEasy
- 4.Add Linked ListsEasy
- 5.Reverse Linked ListMedium
- 6.Detect CycleMedium
- 7.Merge Linked ListsMedium
- 8.Pivot Linked ListHard