# 2816. Double a Number Represented as a Linked List """ given the 'head' of a non-empty linked list representing a non negative integer without leading zeros. return the 'head' of the linked list after doubling it. """ # Definition for singly-linked list. class ListNode(object): def __init__(self, val=0, next=None): self.val = val self.next = next class Solution(object): def doubleIt(self, head): """ :type head: Optional[ListNode] :rtype: Optional[ListNode] """ if head.val > 4: head = ListNode(0, head) node = head while node: node.val = (node.val * 2) % 10 if node.next and node.next.val > 4: node.val += 1 node = node.next return head