中等难度
题目大意:给定单链表,更换排列顺序,将原来位置1234567,更换为1357246.要求空间复杂度为o(1),时间复杂度为o(n).
思路:暴力...
code:
struct ListNode* oddEvenList(struct ListNode* head) {
struct ListNode *p1, *odd, *even;
if(!head||!(head->next)||!(head->next->next)) return head;
odd=head;
even=head->next;
p1=even;
while(odd||even){
odd->next=odd->next->next;
even->next=even->next->next;
odd=odd->next;
even=even->next;
if(!odd->next||!(odd->next->next)) break;
}
odd->next=p1;
return head;
}