Two nonnegative integers are represented by reversed decimal digits in linked lists. Return their sum in the same representation, with one zero digit for zero.
Example 1
Argument 1: next pointers; tail points to null.
Argument 2: next pointers; tail points to null.
Input
l1 = [8,9]
l2 = [7]
Output
[5,0,1]
Explanation
The digits encode 98 and 7; sum 105 is encoded [5,0,1].
Example 2
Argument 1: next pointers; tail points to null.
Argument 2: next pointers; tail points to null.
Input
l1 = [0]
l2 = [0]
Output
[0]
Explanation
Zero plus zero returns one zero digit, not an empty list.
Example 3
Argument 1: next pointers; tail points to null.
Argument 2: next pointers; tail points to null.
Input
l1 = [9,9]
l2 = [1]
Output
[0,0,1]
Explanation
99+1=100; a carry propagates through both nines and creates a third digit.
Constraints
1 <= length of each list <= 100
Digits are 0..9
There are no leading zero digits in the represented numbers except zero itself
Function contractaddTwoNumbersArguments: list, list
Loading draft…
SolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.