码迷,mamicode.com
首页 > 其他好文 > 详细

Odd Even Linked List

时间:2019-07-24 22:27:20      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:return   solution   ext   dev   lin   dde   nod   for   int   

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

标签:return   solution   ext   dev   lin   dde   nod   for   int   

原文地址:https://www.cnblogs.com/wangcl-8645/p/11241192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!