Double a Number Represented as a Linked List

You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.

Return the head of the linked list after doubling it.

Example 1
[1] -> [8] -> [9] -> null
---
[3] -> [7] -> [8] -> null
Inputhead = [1,8,9]
Output[3,7,8]
The linked list represents the number 189, so the returned linked list represents 189 * 2 = 378.
Example 2
[9] -> [9] -> [9] -> null
---
[1] -> [9] -> [9] -> [8] -> null
Inputhead = [9,9,9]
Output[1,9,9,8]
The linked list represents the number 999, so the returned linked list represents 999 * 2 = 1998.

Constraints

  • The number of nodes in the list is in the range [1, 10^4]
  • 0 <= Node.val <= 9
  • The input is generated such that the list represents a number that does not have leading zeros, except the number 0 itself.

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate