Leetcode 328 Odd Even Linked List
这道题是merge two linked list的逆过程,即就是先要分成两个linked list,然后合并到一起即可。
class Solution { public: ListNode* oddEvenList(ListNode* head) { if (head == NULL || head->next == NULL) { return head; } ListNode* first = head; ListNode* second = head->next; ListNode* reserve_second = second; while(second && second->next) { first->next = second->next; first = first->next; second->next = first->next; second = second->next; } first->next = reserve_second; return head; } };