Add Two Number Lists
Two non-negative numbers are stored as linked lists of digits, most significant digit first. Return their sum in the same format.
Linked lists are given and returned as Python lists of node values, from head to tail. Think in terms of nodes and pointers; the list format just makes the tests readable.
Requirements
- Don't convert to integers: push the digits onto stacks and add from the back with a carry.
Examples
EXAMPLE WALKTHROUGHdifferent lengths
A guided view of the published example, not a trace of your code.
INPUT
[[7,2,4,3],[5,6,4]]TASKadd_number_lists()
EXPECTED OUTPUT
[7,8,0,7]Start with the input values shown in this example.
Example 1 of 3
Input: a = [7,2,4,3], b = [5,6,4]
Output: [7,8,0,7]
Explanation: different lengths
Input: a = [2,4,3], b = [5,6,4]
Output: [8,0,7]
Explanation: same length
Input: a = [0], b = [0]
Output: [0]
Explanation: zeros
Hint 1
Stacks let you visit digits from least to most significant.