两根指针,最后把even的指针append到odd的末尾。
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode oddEvenList(ListNode head) {
if(head==null||head.next==null)return head;
ListNode odd = head ;
ListNode even = head.next;
ListNode temp =even;
while(even!=null&&even.next!=null)
{
odd.next=even.next;
odd=odd.next;
even.next=even.next.next;
even=even.next;
}
odd.next=temp;
return head;
}
}