Search⌘ K

Add Two Integers Represented by Linked Lists

Given the head pointers of two linked lists where each linked list represents an integer number (each node is a digit), add them and return the resulting number in a linked list.

Statement

We are given the head pointers of two linked lists, each linked list represents an integer number (each node is a digit). Add them and return the resulting linked list (i.e., sum).

Here, the first node in a list represents the least significant digit.

Example

g head3 result head a3 8 head3->a3 b3 3 a3->b3 c3 1 b3->c3 d3 0 c3->d3 e3 1 d3->e3 f3 NULL e3->f3 head2 head2 a2 7 head2->a2 b2 3 a2->b2 c2 2 b2->c2 d2 NULL c2->d2 head1 head1 a1 1 head1->a1 b1 0 a1->b1 c1 9 b1->c1 d1 9 c1->d1 e1 NULL d1->e1

Sample input

[1, 0, 9, 9]
[7, 3, 2]

Expected output

[8, 3, 1, 0, 1]

Constraints

Only one positive digit (between 00 and 99 ...