class Solution {
public:
ListNode* oddEvenList(ListNode* head) {
if(!head || !head->next || !head->next->next) return head;
ListNode *node1 = head, *node2 = head->next;
ListNode *curr1 = node1, *curr2 = node2;
while(curr2 && curr2->next) {
curr1->next = curr2->next;
curr1 = curr1->next;
curr2->next = curr1->next;
curr2 = curr2->next;
}
curr1->next = node2;
return node1;
}
};
LeetCode328. 奇偶链表
最新推荐文章于 2024-05-25 23:03:49 发布