Skip to content

Instantly share code, notes, and snippets.

@lavakush-m-tiwari
Created April 19, 2022 15:41
Show Gist options
  • Save lavakush-m-tiwari/3a3d72bce0715986d89677ac36d2da09 to your computer and use it in GitHub Desktop.
Save lavakush-m-tiwari/3a3d72bce0715986d89677ac36d2da09 to your computer and use it in GitHub Desktop.
ListNode* oddEvenList(ListNode* head) {
if (!head) return nullptr;
ListNode *odd = head, *even = head->next, *evenHead = even;
while (odd->next && even->next) {
odd->next = even->next;
odd = odd->next;
even->next = odd->next;
even = even->next;
}
odd->next = evenHead;
return head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment