Problem 2816
unknown
typescript
2 years ago
466 B
11
Indexable
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;
};Editor is loading...