Add Two Numbers
You are given two non-empty linked lists l1 and l2 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, also in reverse order.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Example 1
[2] -> [4] -> [3] -> null [5] -> [6] -> [4] -> null --- [7] -> [0] -> [8] -> null
Input
l1 = [2,4,3], l2 = [5,6,4]Output
[7,0,8]342 plus 465 equals 807, so the returned list is 7 -> 0 -> 8.
Example 2
[0] -> null [0] -> null --- [0] -> null
Input
l1 = [0], l2 = [0]Output
[0]Both lists represent 0, so their sum is 0.
Constraints
- The number of nodes in each linked list is in the range [1, 100]
- 0 <= Node.val <= 9
- It is guaranteed that the list represents a number that does not have leading zeros, except the number 0 itself