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;
}}

京公网安备 11010502036488号