Radix Addition

Start Timer

0:00:00

Upvote
3
Downvote
Save question
Mark as completed
View comments (2)

You are given two non-empty linked lists representing two non-negative integers. Each list contains a single number, where each item in the list is one digit. The digits are stored in reverse order.

Task: Add the two numbers and return the sum as a linked list, also with the digits in reverse order. You may assume the two numbers do not contain any leading zeros, except the number 0 itself.

Example 1:

Input:

l1 = 2->4->3->null
l2 = 5->6->4->null

Output:

addTwoNumbers(l1, l2) = 7->0->8->null

Explanation: 342 + 465 = 807.

Example 2:

Input:

l1 = 0->null
l2 = 0->null

Output:

addTwoNumbers(l1, l2) -> 0->null

Explanation: 0 + 0 = 0.

.
.
.
.
.


Comments

Loading comments