The problem. Two non-negative numbers are stored as linked lists, one digit per node, in reverse order (the ones digit comes first). Add the two numbers and return the sum as a linked list in the same reverse order.
Input: l1 = [2, 4, 3], l2 = [5, 6, 4]
Output: [7, 0, 8] 342 + 465 = 807
Input: l1 = [9, 9, 9, 9, 9, 9, 9], l2 = [9, 9, 9, 9]
Output: [8, 9, 9, 9, 0, 0, 0, 1]The reverse order is a gift: it's exactly the order you add in by hand — ones first, then tens, carrying as you go. The numbers can have up to 100 digits, far beyond what a normal integer can hold.
Free account
Sign up to read the rest of this lesson: 5 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come