358. Add Two Numbers II (No Reverse Allowed)

MediumLinked ListLinked ListStackMath

You are given two non-empty linked lists representing two non-negative integers, where the most significant digit comes first. Add the two numbers and return the sum as a linked list in the same most-significant-first order, without reversing the input lists. Lists are given as arrays. Input: '[l1], [l2]'.

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

Output: Array — the sum digits (MSB first).

Examples

Example 1
Input: [7,2,4,3], [5,6,4]
Output: [7,8,0,7]
Explanation: 7243 + 564 = 7807.
Example 2
Input: [2,4,3], [5,6,4]
Output: [8,0,7]
Explanation: 243 + 564 = 807.
Example 3
Input: [0], [0]
Output: [0]
Explanation: 0 + 0 = 0.

Constraints

Asked by

BloombergMicrosoftOracleGoogleAmazonMeta
Solve this problem in the editor →