#2816

Double a Number Represented as a Linked List

specialist · 690 · lc medium +30 · verified · 61.3% accepted · 1,279 likes · top 61%

Description

The head of a non-empty linked list representing a non-negative integer without leading zeros is given.

Double the number the list represents and return the head of the updated linked list.

Example 1:

Input: head = [1,8,9]
Output: [3,7,8]
Explanation: The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.

Example 2:

Input: head = [9,9,9]
Output: [1,9,9,8]
Explanation: The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998.

Code

1
2
3
4
5
6
7
8