Odd Even Linked List

Posted wangcl-8645

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Odd Even Linked List相关的知识,希望对你有一定的参考价值。

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

 

以上是关于Odd Even Linked List的主要内容,如果未能解决你的问题,请参考以下文章

Odd Even Linked List

Odd Even Linked List

Leetcode Odd Even Linked List

328. Odd Even Linked List

LC_328. Odd Even Linked List

No. 328. Odd Even Linked List