357. Add Two Numbers (Linked List Addition)

MediumLinked ListLinked ListMath

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order (least significant digit first), one digit per node. Add the two numbers and return the sum as a linked list, also in reverse order. Lists are given as arrays. Input: '[l1], [l2]'.

Input: '[l1], [l2]'.

Output: Array — the sum digits (reverse order).

Examples

Example 1
Input: [2,4,3], [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.
Example 2
Input: [0], [0]
Output: [0]
Explanation: 0 + 0 = 0.
Example 3
Input: [9,9,9], [1]
Output: [0,0,0,1]
Explanation: 999 + 1 = 1000.

Constraints

Asked by

AdobeBloombergMicrosoftAmazonGoogleMeta
Solve this problem in the editor →