86 
class Solution {
public ListNode partition(ListNode head, int x) {
ListNode lowheader=new ListNode(0);
ListNode low=lowheader;
ListNode highheader=new ListNode(0);
ListNode high=highheader;
while(head!=null){
if(head.val<x){
low.next=head;
head=head.next;
low=low.next;
low.next=null;
}else{
high.next=head;
head=head.next;
high=high.next;
high.next=null;
}
}
low.next=highheader.next;
return lowheader.next; }
}

148

class Solution {
public ListNode sortList(ListNode head) {
while(head==null||head.next==null){
return head;
}
ListNode fast=head,low=head;
ListNode pre=null;
while(fast!=null&&fast.next!=null){
pre=low;
low=low.next;
fast=fast.next.next;
}
pre.next=null;
ListNode left=sortList(head);
ListNode right=sortList(low);
ListNode dummy=new ListNode(0);
ListNode curr=dummy;
while(left!=null&&right!=null){
if(left.val<right.val){
curr.next=left;
left=left.next;
curr=curr.next;
}else{
curr.next=right;
right=right.next;
curr=curr.next;
}
}
if(left==null){
curr.next=right;
}
if(right==null){
curr.next=left;
}
return dummy.next;
}
}

leetcode(java)的更多相关文章

  1. leetcode:283. Move Zeroes(Java)解答

    转载请注明出处:z_zhaojun的博客 原文地址:http://blog.csdn.net/u012975705/article/details/50493772 题目地址:https://leet ...

  2. leetcode:238. Product of Array Except Self(Java)解答

    转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Product of Array Except Self Given an array of n integers where n > ...

  3. leetcode:122. Best Time to Buy and Sell Stock II(java)解答

    转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Best Time to Buy and Sell Stock II Say you have an array for which th ...

  4. 【剑指Offer】不用加减乘除做加法 解题报告(Java)

    [剑指Offer]不用加减乘除做加法 解题报告(Java) 标签(空格分隔): 剑指Offer 题目地址:https://www.nowcoder.com/ta/coding-interviews 题 ...

  5. 如何夯实(Java)编程基础,并深入学习和提高

    如何夯实(Java)编程基础,并深入学习和提高? 240赞同反对,不会显示你的姓名 匿名用户 240 人赞同 多学习...网上自学的学习网站很多,见以下榜单~一.汇总榜单: 公开课_学习网站导航 收录 ...

  6. TCL校园招聘——软件开发工程师(java) 只招5个。。。

    简介 TCL集团股份有限公司创立于1981年,是全球性规模经营的消费类电子企业集团之一,广州2010年亚运会合作伙伴,总部位于广东省惠州市仲恺高新区TCL科技大厦.旗下拥有TCL集团.TCL多媒体科技 ...

  7. UEditor上传图片到七牛云储存(java)

    我们的网站一般放在虚拟空间或者服务器上,图片如果存在本地目录,会占用很多空间和流量,还增加了负担,好的办法是把图片存放到云储存服务里面,平时用url去拿 云储存:普遍说又拍云和七牛比较好,看到七牛免费 ...

  8. 开源工作流 Bonita BPM (JAVA)

    Bonita BPM 开源工作流 Bonita BPM  (JAVA) http://www.bonitasoft.com/

  9. ZeroMQ(java)中对IO的封装(StreamEngine)

    哎,各种各样杂七杂八的事情...好久没有看代码了,其实要搞明白一个与IO相关的框架,最好的办法就是把它的I/0的读写两个过程搞清楚...例如在netty中,如果能将eventLoop的运行原理搞清楚, ...

随机推荐

  1. 快速傅立叶变换(FFT)算法

    已知多项式f(x)=a0+a1x+a2x2+...+am-1xm-1, g(x)=b0+b1x+b2x2+...+bn-1xn-1.利用卷积的蛮力算法,得到h(x)=f(x)g(x),这一过程的时间复 ...

  2. sweetalert弹窗的使用

    之前接触到layer弹出层,今天又发现了一个非常实用的弹出层插件,它的名字叫做sweetalert. 官网地址:http://t4t5.github.io/sweetalert/ npm下载方式:np ...

  3. js 模拟css3 动画1

    <html> <head> <title> javaScript缓动入门 </title> </head> <body> < ...

  4. 30_react_router基本使用

    项目结构: import React from 'react' import {render} from 'react-dom' import {BrowserRouter} from 'react- ...

  5. springBoot框架的搭建

    1新建一个项目: 2.注意选择JDK1.8,和选择spring initializr加载springBoot相关jar包: 3.下一步next: 4.下一步next,选择Web和MyBatis然后ne ...

  6. 资产管理平台 glpi

    1.安装apache yum install httpdyum install httpd-devel 2.安装php 3.配置apache支持php 4.下载glpi并解压 5.配置apache 6 ...

  7. Android Studio模拟器磁盘空间不足(Not enough disk space to run AVD)

    在Android Studio中运行模拟器时,提示Error: Not enough disk space to run AVD '....'. Exiting.是说安装模拟的磁盘空间不足,导致无法运 ...

  8. spring @transactional 注解事务

    1.在spring配置文件中引入<tx:>命名空间 <beans xmlns="http://www.springframework.org/schema/beans&qu ...

  9. js调起微信客户端

    function openWx(){ locatUrl = "weixin://"; if(/ipad|iphone|mac/i.test(navigator.userAgent) ...

  10. BM递推

    从别的大佬处看到的模板 #include<bits/stdc++.h> #define fi first #define se second #define INF 0x3f3f3f3f ...