📘
Add Two Numbers
MediumLinked Lists
Given two non-negative integers represented as arrays of digits in reverse order (least significant digit first), return their sum as an array in the same reverse order.
Each element contains a single digit. The numbers do not have leading zeros except the number 0 itself.
Output as space-separated digits.
Example:
Input:
2,4,3 5,6,4
Output:
7 0 8
Reasoning:
- The input arrays represent numbers in reverse order: 2⋅102+4⋅101+3⋅100=243 and 5⋅102+6⋅101+4⋅100=564.
- We add these two numbers: 243+564=807.
- To get the output, we convert the sum back to an array of digits in reverse order: 807 becomes 7, 0, 8.
- The final output is the sum as an array in the same reverse order, with space-separated digits: 708.
Constraints:
- 1 <= len(l1), len(l2) <= 100
- 0 <= l1[i], l2[i] <= 9
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.