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