题解 | #链表的奇偶重排#
链表的奇偶重排
http://www.nowcoder.com/practice/02bf49ea45cd486daa031614f9bd6fc3
public class Solution {
/** 用双指针 */ public ListNode oddEvenList (ListNode head) { // write code here if(head==null) return null; ListNode dummy=new ListNode(-1); dummy.next=head; ListNode head1=head.next; ListNode p1=head; ListNode p2=head.next; while(p1.next!=null && p2.next!=null){ p1.next=p2.next; p1=p1.next; p2.next=p1.next; p2=p2.next; } p1.next=head1; return dummy.next; }
}