点击打开链接
//奇偶调换
class Solution {
public:
ListNode* oddEvenList(ListNode* head) {
if(!head || !head->next) return head;
ListNode* pre = head, *cur=head->next;
while (cur && cur->next) {
ListNode* tmp = pre->next;
pre->next = cur->next;
cur->next = cur->next->next;
pre->next->next = tmp;
pre = pre->next;
cur = cur->next;
}
return head;
}
};