Double the non-negative integer stored in a linked list of digits and return the resulting list.
You are given the head of a singly linked list where each node contains a single decimal digit. The digits represent a non-negative integer in forward order, with the most significant digit at the head.
Return the head of a linked list representing the number obtained by doubling the original value.
The returned list should also store digits in forward order. If doubling creates a new most significant digit, include it in the result.
Input Format
- A singly linked list
head, where each node contains one digit0through9. - The list represents a non-negative integer in forward order.
Output Format
- Return the head of a singly linked list representing
2 × value(head)in forward order.
Constraints
- The number of nodes is at least 1.
- Each node contains a single digit from
0to9. - The input represents a valid non-negative integer with no leading zeros unless the number is zero itself.
- The result may contain one extra digit due to carry.
Example 1
Input
head = [1,8,9]
Output
[3,7,8]
Explanation
189 doubled is 378, so the resulting linked list is [3,7,8].
Example 2
Input
head = [9,9,9]
Output
[1,9,9,8]
Explanation
999 doubled is 1998, which requires an extra leading digit.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.