Back to course home
0% completed
Vote For New Content
Add Two Numbers (medium)
Problem Statement
You are given two non-empty linked lists that represent two non-negative
integers, where each node contains the single digit. The digits are stored in reverse order
. Add these two numbers and return the sum as a linked list.
You can assume the numbers do not have leading zeros, except for the number 0 itself.
Examples
Example 1:
- Input: l1: [1, 2, 3], l2: [4, 5, 6]
- Expected Output: [5, 7, 9]
- Justification: 321 + 654 = 975, which in reverse order is [5, 7, 9].
Example 2:
- Input: l1: [7, 8], l2: [6, 7, 8, 9]
- Expected Output: [3, 6, 9, 9]
- Justification: 87 + 9876 = 9963, which in reverse order is [3, 6, 9, 9].
Example 3:
- Input: l1: [0], l2: [0]
- Expected Output: [0]
- Justification: 0 + 0 = 0, which in reverse order 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.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself