Problem 2816
unknown
typescript
a year ago
466 B
2
Indexable
Never
function doubleIt(head: ListNode | null): ListNode | null { if(head === null) { return head; } const root = new ListNode(1, head); const noMore = head.val < 5; while(head.next !== null) { head.val = (head.val * 2) % 10; if(head.next.val * 2 > 9) { head.val++; } head = head.next; } head.val = (head.val * 2) % 10; return noMore ? root.next : root; };