代码:
class Solution328_medium {
public:
ListNode* oddEvenList(ListNode* head) {
if (nullptr == head || nullptr == head->next)
return head;
ListNode* odd_head = head, * odd = head;
ListNode* even_head = head->next, * even = head->next;
while (nullptr != odd && nullptr != even) {
odd->next = even->next;
odd = odd->next;
if (nullptr != odd)
even->next = odd->next;
even = even->next;
}
odd = odd_head;
while (nullptr != odd->next)
odd = odd->next;
odd->next = even_head;
return odd_head;
}
};