Skip to content

Commit

Permalink
Solution to #16
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatr21 committed May 17, 2020
1 parent d8b1deb commit dcd73ae
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Solutions/S16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/

ListNode* oddEvenList(ListNode* head) {
if(!head) return NULL;
else {
ListNode *odd = head, *even = head->next, *evenHead = even;
while(even && even->next)
{
odd->next = even->next;
odd = odd->next;
even->next = odd->next;
even = even->next;
}
odd->next = evenHead;
return head;
}
}

0 comments on commit dcd73ae

Please sign in to comment.