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. 3Sum

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  2. IE hack中主要的几个

    _: IE6; #*+.: IE6 IE7; black\0: IE8; black\9: IE所有; @media screen\9 { … }: IE6 IE7; @media \0screen\ ...

  3. javascript 变量,作用域,内存管理小结

    js的变量保存两种类型的数据——基本数据类型与引用类型.具有以下几点特征:   变量: 1)基本类型值在内存中占固定大小的空间,因此被保存在栈内存中; 2) 把保存基本类型值得变量赋给另一个变量,会创 ...

  4. respond.js

    Respond.js,低版本浏览器也能够支持媒体查询 在之前有篇文章也是介绍IE6,7,8支持媒体查询的(查看),Respond.js这个比css3-mediaqueries更为强大一些,它可以支持l ...

  5. Python 基础 - 随机列表最大的两个值

    # -*- coding: utf-8 -*- #author:v def sywmemeda(l): #list 冒泡排序 length = len(l) for i in range(length ...

  6. PHP版本VC6与VC9、Thread Safe与None-Thread Safe等的区别

    PHP版本VC6与VC9.Thread Safe与None-Thread Safe等的区别 [摘要]PHP 是一种 HTML 内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言,在PHP发 ...

  7. Hibernate配置Log4J,很有参考价值的

    hibernate3 自带的默认的日志框架是slf4j,hibernate3的slf只是一个日志的接口,而hibernate3 自带默认的日志框架,在实际开发中很少有公司或者是项目中用到,这里记录一种 ...

  8. angular 路由去除#号

    1.  路由启动          $locationProvider.html5Mode(true);  通过pushstatex修改url app.js define([ 'angular', & ...

  9. vmware centos下配置ip

    使用NAT模式 虚拟机网络连接使用NAT模式,物理机网络连接使用Vmnet8. 虚拟机设置里面--网络适配器,网络连接选择NAT模式. 虚拟机菜单栏-编辑-虚拟网络编辑器,选择Vmnet8 NAT模式 ...

  10. iOS,XMPP本地环境搭建和框架使用

    1.XMPP的MySQL和openfire环境配置 2.XmppFramework框架导入和介绍 XMPP的MySQL和openfire环境配置 1.下载mysql安装 mysql下载 打开MySQL ...