<p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>

<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example.png" style="width: 401px; height: 81px;" />
<pre>
<strong>Input:</strong> head = [1,8,9]
<strong>Output:</strong> [3,7,8]
<strong>Explanation:</strong> 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.
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example2.png" style="width: 401px; height: 81px;" />
<pre>
<strong>Input:</strong> head = [9,9,9]
<strong>Output:</strong> [1,9,9,8]
<strong>Explanation:</strong> 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. 
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in the list is in the range <code>[1, 10<sup>4</sup>]</code></li>
	<li><font face="monospace"><code>0 &lt;= Node.val &lt;= 9</code></font></li>
	<li>The input is generated such that the list represents a number that does not have leading zeros, except the number <code>0</code> itself.</li>
</ul>

# 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]:
        pass
















# 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]:
        
        def recursion(node):
            if not node:
                return 0
            carry = recursion(node.next)
            node.val = node.val * 2 + carry
            carry = node.val // 10
            node.val = node.val % 10
            return carry

        carry = recursion(head)
        if carry:
            head_new = ListNode(val=carry, next=head)
            return head_new
        return head






class Solution:
    def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:
        head_dummy = ListNode(next=head)
        node = head
        prev = head_dummy
        while node:
            node.val *= 2
            carry = node.val // 10
            node.val %= 10
            if carry:
                prev.val += 1
            
            prev = node
            node = node.next
        if head_dummy.val:
            return head_dummy
        return head


class Solution:
    def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:
        head_dummy = ListNode(val=0, next=head)
        node = head_dummy
        while node:
            node.val *= 2
            node.val %= 10
            
            if node.next and node.next.val >= 5:
                node.val += 1
                
            node = node.next

        if head_dummy.val:
            return head_dummy
        return head




















# 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]:
        head_dummy = ListNode(next=head)
        prev = head_dummy
        node = head
        while node:
            node.val = node.val * 2
            carry = node.val // 10
            node.val = node.val % 10
            if carry:
                prev.val += 1
            prev = node
            node = node.next

        return head_dummy if head_dummy.val else head



# 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]:
        head_dummy = ListNode(next=head)
        node = head_dummy
        while node:
            node.val *= 2
            node.val %= 10
            if node.next and node.next.val >= 5:
                node.val += 1
            node = node.next
        return head_dummy if head_dummy.val else head




























# 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]:
        head_dummy = ListNode(next=head)
        node = head_dummy
        while node:
            node.val *= 2
            node.val %= 10
            if node.next and node.next.val >= 5:
                node.val += 1
            node = node.next
        return head_dummy if head_dummy.val else head
























# 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]:
        head_new = ListNode(next=head)
        
        node = head_new
        while node:
            node.val = (node.val * 2) % 10
            if node.next and node.next.val >= 5:
                node.val += 1
            node = node.next
        return head_new if head_new.val != 0 else head























class Solution:
    def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:
        head_dummy = ListNode(next=head)
        node = head_dummy
        while node:
            node.val = (node.val * 2) % 10
            if node.next and node.next.val * 2 >= 10:
                node.val += 1
            node = node.next
        return head_dummy if head_dummy.val else head
19600