1ms Java simple solution


  • 3
    S

    public class OddEvenLinkedList {

    public static ListNode oddEvenList(ListNode head) {
    	if (head == null || head.next == null)
    		return head;
    	ListNode even_head = head.next;
    	ListNode odd = head, even = even_head;
    	while (even != null && even.next != null) {
    		odd.next = even.next;
    		even.next = even.next.next;
    		odd = odd.next;
    		even = even.next;
    	}
    	odd.next = even_head;
    	return head;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.