/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     public int val;
 *     public ListNode next;
 *     public ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public ListNode OddEvenList(ListNode head) {
        if(head==null||head.next==null)
            return head;
        ListNode node=new ListNode(0);
        node.next=head;
        ListNode odd=head;
        ListNode even=head.next;
       
        while(even!=null&&even.next!=null){
            ListNode temp=odd.next ;
         odd.next=even.next;
            even.next=even.next.next;
            odd.next.next=temp;
            odd=odd.next;
            even=even.next;
        }
        return head;
    }
}

 

 posted on 2019-07-24 22:04  JetaimeBeaucoup  阅读(70)  评论(0编辑  收藏  举报