Description
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each node contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Examples
Input:
l1 = [2,4,3], l2 = [5,6,4]Output:
[7,0,8]Explanation:
342 + 465 = 807, stored in reverse as [7,0,8].
Input:
l1 = [9,9,9], l2 = [1]Output:
[0,0,0,1]Explanation:
999 + 1 = 1000.
Input:
l1 = [8,7,2], l2 = [3,9,5,1]Output:
[1,7,8,1]Explanation:
278 + 1593 = 1871. The numbers are represented in reverse order, so l1 represents 278 and l2 represents 1593. The sum 1871 is stored in reverse as [1,7,8,1].
Constraints
- •
The number of nodes in each linked list is in the range [1, 100]. - •
0 ≤ Node.val ≤ 9