Algorithms
Medium
2816
2871
Double a Number Represented as a Linked List
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:

[https://assets.leetcode.com/uploads/2023/05/28/example.png]

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:

[https://assets.leetcode.com/uploads/2023/05/28/example2.png]

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.


Constraints:

 * The number of nodes in the list is in the range [1, 104]
 * 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.
"""
# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:
        
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:

[https://assets.leetcode.com/uploads/2023/05/28/example.png]

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:

[https://assets.leetcode.com/uploads/2023/05/28/example2.png]

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.


Constraints:

 * The number of nodes in the list is in the range [1, 104]
 * 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.


Please complete the code below to solve above prblem:
```python
# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:
        
```

my_solution = Solution()

_f1 = lambda lst: ListNode(lst[0], _f1(lst[1:])) if lst else None
_f2 = lambda node: [node.val] + _f2(node.next) if node else []


test_input = { "head": _f1([1,8,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,7,8]

test_input = { "head": _f1([9,9,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,9,9,8]

test_input = { "head": _f1([0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [0]

test_input = { "head": _f1([1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2]

test_input = { "head": _f1([2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4]

test_input = { "head": _f1([3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6]

test_input = { "head": _f1([4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8]

test_input = { "head": _f1([5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0]

test_input = { "head": _f1([6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2]

test_input = { "head": _f1([7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4]

test_input = { "head": _f1([8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6]

test_input = { "head": _f1([9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8]

test_input = { "head": _f1([1,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,0]

test_input = { "head": _f1([1,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,2]

test_input = { "head": _f1([1,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,4]

test_input = { "head": _f1([1,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,6]

test_input = { "head": _f1([1,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,8]

test_input = { "head": _f1([1,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,0]

test_input = { "head": _f1([1,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,2]

test_input = { "head": _f1([1,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,4]

test_input = { "head": _f1([1,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,6]

test_input = { "head": _f1([1,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,8]

test_input = { "head": _f1([2,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,0]

test_input = { "head": _f1([2,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,2]

test_input = { "head": _f1([2,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,4]

test_input = { "head": _f1([2,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,6]

test_input = { "head": _f1([2,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,8]

test_input = { "head": _f1([2,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,0]

test_input = { "head": _f1([2,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,2]

test_input = { "head": _f1([2,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,4]

test_input = { "head": _f1([2,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,6]

test_input = { "head": _f1([2,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,8]

test_input = { "head": _f1([3,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,0]

test_input = { "head": _f1([3,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,2]

test_input = { "head": _f1([3,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,4]

test_input = { "head": _f1([3,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,6]

test_input = { "head": _f1([3,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,8]

test_input = { "head": _f1([3,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,0]

test_input = { "head": _f1([3,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,2]

test_input = { "head": _f1([3,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,4]

test_input = { "head": _f1([3,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,6]

test_input = { "head": _f1([3,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,8]

test_input = { "head": _f1([4,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,0]

test_input = { "head": _f1([4,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,2]

test_input = { "head": _f1([4,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,4]

test_input = { "head": _f1([4,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,6]

test_input = { "head": _f1([4,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,8]

test_input = { "head": _f1([4,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,0]

test_input = { "head": _f1([4,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,2]

test_input = { "head": _f1([4,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,4]

test_input = { "head": _f1([4,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,6]

test_input = { "head": _f1([4,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,8]

test_input = { "head": _f1([5,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,0]

test_input = { "head": _f1([5,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,2]

test_input = { "head": _f1([5,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,4]

test_input = { "head": _f1([5,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,6]

test_input = { "head": _f1([5,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,8]

test_input = { "head": _f1([5,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,0]

test_input = { "head": _f1([5,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,2]

test_input = { "head": _f1([5,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,4]

test_input = { "head": _f1([5,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,6]

test_input = { "head": _f1([5,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,8]

test_input = { "head": _f1([6,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,0]

test_input = { "head": _f1([6,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,2]

test_input = { "head": _f1([6,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,4]

test_input = { "head": _f1([6,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,6]

test_input = { "head": _f1([6,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,8]

test_input = { "head": _f1([6,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,0]

test_input = { "head": _f1([6,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,2]

test_input = { "head": _f1([6,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,4]

test_input = { "head": _f1([6,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,6]

test_input = { "head": _f1([6,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,8]

test_input = { "head": _f1([7,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,0]

test_input = { "head": _f1([7,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,2]

test_input = { "head": _f1([7,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,4]

test_input = { "head": _f1([7,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,6]

test_input = { "head": _f1([7,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,8]

test_input = { "head": _f1([7,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,0]

test_input = { "head": _f1([7,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,2]

test_input = { "head": _f1([7,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,4]

test_input = { "head": _f1([7,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,6]

test_input = { "head": _f1([7,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,8]

test_input = { "head": _f1([8,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,0]

test_input = { "head": _f1([8,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,2]

test_input = { "head": _f1([8,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,4]

test_input = { "head": _f1([8,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,6]

test_input = { "head": _f1([8,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,8]

test_input = { "head": _f1([8,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,0]

test_input = { "head": _f1([8,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,2]

test_input = { "head": _f1([8,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,4]

test_input = { "head": _f1([8,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,6]

test_input = { "head": _f1([8,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,8]

test_input = { "head": _f1([9,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,0]

test_input = { "head": _f1([9,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,2]

test_input = { "head": _f1([9,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,4]

test_input = { "head": _f1([9,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,6]

test_input = { "head": _f1([9,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,8]

test_input = { "head": _f1([9,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,9,0]

test_input = { "head": _f1([9,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,9,2]

test_input = { "head": _f1([9,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,9,4]