385. Double a Number Represented as a Linked List

MediumLinked ListLinked ListMath

Given a non-negative integer represented as a linked list of digits with the most significant digit first, return the linked list representing twice that number (also most significant digit first). Return the result as an array.

Input: An array of digits (MSB first).

Output: Array — the doubled number's digits.

Examples

Example 1
Input: [1,8,9]
Output: [3,7,8]
Explanation: 189 * 2 = 378.
Example 2
Input: [9,9,9]
Output: [1,9,9,8]
Explanation: 999 * 2 = 1998.
Example 3
Input: [0]
Output: [0]
Explanation: 0 * 2 = 0.

Constraints

Asked by

AmazonMicrosoftGoogle
Solve this problem in the editor →