Problem
Two non-negative whole numbers are stored as linked lists, one digit per node, with the most significant digit first (the way you write numbers). Add them and return the sum as a linked list in the same order.
Example 1
- Input
- 7
- Output
- 2 -> 4 -> 3 + 5 -> 6 -> 4 → 7 -> 8 -> 0 -> 7
- Why
- 7243 + 564 = 7807
Example 2
- Input
- 2
- Output
- 4 -> 3 + 5 -> 6 -> 4 → 8 -> 0 -> 7
- Why
- 243 + 564 = 807
Example 3
- Input
- 0 + 0
- Output
- 0
The numbers can be far too long to fit in a regular integer. Try not to reverse the input lists.
Constraints
1 <= number of nodes in each list <= 1000 <= Node.val <= 9Neither number has leading zeros, except the number 0 itself.