Add Two Numbers II
Problem statement
Two nonnegative integers are stored in forward digit order in linked lists l1 and l2. Return their sum as a forward-order digit list.
Do not reverse or mutate the input lists.
Function
addTwoNumbersForward(l1: ListNode, l2: ListNode) → ListNodeExamples
Example 1
l1 = [7,2,4,3]l2 = [5,6,4]return = [7,8,0,7]7243 + 564 = 7807.
Example 2
l1 = [9,9]l2 = [1]return = [1,0,0]The final carry becomes the new head.
Constraints
- Each list has between
1and100nodes. - Every node value is a decimal digit.