public class Solution
{
public ListNode OddEvenList(ListNode head)
{
if(head == null || head.next == null || head.next.next == null) return head; //考虑特殊情况,0、1、2个点,直接返回
ListNode res = head,a = head; //a遍历奇数点 res记录奇数最开始的点
ListNode bb=head.next,b = head.next; //b遍历偶数点 bb 记录偶数最开始的点
while (a.next != null && a.next.next !=null) {
a.next = a.next.next;
b.next = b.next.next;
a = a.next;
b = b.next;
}
if (a.next != null)
{
b.next = null;
}
a.next = bb;
return res;
}
}

odd_even_list的更多相关文章

随机推荐

  1. [LintCode] LRU Cache 缓存器

    Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...

  2. 关于JS的算法

    一.快速排序 function qSort(arr) { if(arr.length === 0) { return []; } var left = []; var right = []; var ...

  3. eclipse中如何修改dynamic web module version

    java项目中,若切换服务器,经常会涉及到动态web模块版本的问题.      比如:新建了web项目,开始使用tomcat服务器,但是后来使用jboss服务器,就会出现:Project facet ...

  4. js简单显示和隐藏div,触发超链接,动态更改button值,setInterval()简单使用,jquery easyui弹出框简单使用 .

    js简单显示和隐藏div .<!DOCTYPE html> .<html> .<head> .<meta charset="UTF-8"& ...

  5. JS的Touch事件们,触屏时的js事件

    丫的,终于找到了JS在平板电脑上的事件!!!   iphone.ipod Touch.ipad触屏时的js事件   1.Touch事件简介   pc上的web页面鼠标会产生onmousedown.on ...

  6. EmguCV 简单图形绘制

    一.圆 public static void cvCircle( IntPtr img, System.Drawing.Point center, //Center of the circle int ...

  7. SPOJ 10628 Count on a tree(Tarjan离线LCA+主席树求树上第K小)

    COT - Count on a tree #tree You are given a tree with N nodes.The tree nodes are numbered from 1 to  ...

  8. angularJs表单校验(超级详细!!!)

    html代码 <!DOCTYPE html> <html ng-app="angularFormCheckModule"> <head> < ...

  9. J2EE用户CPU占用过大后的分析过程

        1.找到最耗CPU的java线程ps命令 命令:ps -mp pid -o THREAD,tid,time   或者  ps -Lfp pid 结果展示:            2.可以获取到 ...

  10. 【后台测试】Linux下小试jmeter

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处.  转载请注明出处:http://www.cnblogs.com/by-dream/p/5784288.html 前言 上一篇主要讲了在Window ...