odd_even_list
- 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的更多相关文章
随机推荐
- [LintCode] Paint Fence 粉刷篱笆
There is a fence with n posts, each post can be painted with one of the k colors.You have to paint a ...
- 用一段JS代码来比较各浏览器的极限内存与运算速度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 对Oracle10g rac ons服务的一些理解
1.什么是ONS ONS(Oracle Notification Service)是Oracle Clusterware 实现FAN Event Push模型的基础. 在传统模型中,客户端需要 ...
- 执行JDBC的executeUpdate()方法时,报错:数据类型不一致,应为number,但却为binary
该原因是因为,在拼写update语句的时候将一个number类型的字段的值赋为了null导致的,如果想将一个number类型的字清空,不能使用null,可以使用“”来替代.
- 将Excel数据导入mysql数据库的几种方法
将Excel数据导入mysql数据库的几种方法 “我的面试感悟”有奖征文大赛结果揭晓! 前几天需要将Excel表格中的数据导入到mysql数据库中,在网上查了半天,研究了半天,总结出以下几种方法,下面 ...
- IOS第一天多线程-04GCD通信
**** #define HMGlobalQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) #define HMM ...
- MyEclipse 8.5整合Git,并在Github上发布项目【转】
最近Git火得如日中天,而且速度体验和团队模式都很不错.手头正好有个学生实训项目,时间紧任务重,而且学校内网管理太紧,所以就想借助于Internet的分布式开发,因此想到了Github. 经过一天的调 ...
- PRAGMA AUTONOMOUS_TRANSACTION
转自 http://blog.csdn.net/pan_tian/article/details/7675800 这段时间遇到一个问题,程序里明明插入了一条记录,但在后边的一段Procedure中却查 ...
- IEnumerable和IEnumerator
概述 IEnumerable和IEnumerator接口存在的意义:用来实现迭代的功能! public interface IEnumerable { IEnumerator GetEnumerato ...
- Synchronized 个人深解
1.synchronized方法相当于synchronized(this) Synchronized 方法是锁的当前对象,同一个对象的2个synchronized方法被2个线程调用会发生 ...