链表的题目,一定要想明白了再写,否则会越写越乱,想明白了很简单( •̀ ω •́ )✧
public ListNode oddEvenList(ListNode head) {
if(head==null)
return head;
ListNode p=head,q=head.next,r=p,s=q;
while(p!=null&&q!=null) {
if(q.next==null)
break;
p.next=q.next;
p=p.next;
q.next=p.next;
q=q.next;
}
p.next=s;
return r;
}
1ms beats 100%