#C4603. Add Two Numbers Represented by Linked Lists

    ID: 48160 Type: Default 1000ms 256MiB

Add Two Numbers Represented by Linked Lists

Add Two Numbers Represented by Linked Lists

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list, also in reverse order.

The addition must be performed digit by digit, carrying over any value greater than or equal to 10 to the next digit. The input linked lists are provided as sequences of digits via standard input, and the resulting linked list (also a sequence of digits in reverse order) should be printed to standard output.

For example, if the input linked lists represent the numbers 342 and 465, then their sum is 807, and the resulting linked list should be [7, 0, 8].

Note: The input will consist of two lines. The first line contains the digits of the first linked list separated by spaces, and the second line contains the digits of the second linked list separated by spaces.

inputFormat

The input consists of exactly two lines:

  • The first line contains space-separated integers representing the digits of the first number in reverse order.
  • The second line contains space-separated integers representing the digits of the second number in reverse order.

outputFormat

Output a single line containing space-separated integers representing the digits of the sum (in reverse order).

## sample
2 4 3
5 6 4
7 0 8