leetcode(java)
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)的更多相关文章
- leetcode:283. Move Zeroes(Java)解答
转载请注明出处:z_zhaojun的博客 原文地址:http://blog.csdn.net/u012975705/article/details/50493772 题目地址:https://leet ...
- leetcode:238. Product of Array Except Self(Java)解答
转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Product of Array Except Self Given an array of n integers where n > ...
- 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 ...
- 【剑指Offer】不用加减乘除做加法 解题报告(Java)
[剑指Offer]不用加减乘除做加法 解题报告(Java) 标签(空格分隔): 剑指Offer 题目地址:https://www.nowcoder.com/ta/coding-interviews 题 ...
- 如何夯实(Java)编程基础,并深入学习和提高
如何夯实(Java)编程基础,并深入学习和提高? 240赞同反对,不会显示你的姓名 匿名用户 240 人赞同 多学习...网上自学的学习网站很多,见以下榜单~一.汇总榜单: 公开课_学习网站导航 收录 ...
- TCL校园招聘——软件开发工程师(java) 只招5个。。。
简介 TCL集团股份有限公司创立于1981年,是全球性规模经营的消费类电子企业集团之一,广州2010年亚运会合作伙伴,总部位于广东省惠州市仲恺高新区TCL科技大厦.旗下拥有TCL集团.TCL多媒体科技 ...
- UEditor上传图片到七牛云储存(java)
我们的网站一般放在虚拟空间或者服务器上,图片如果存在本地目录,会占用很多空间和流量,还增加了负担,好的办法是把图片存放到云储存服务里面,平时用url去拿 云储存:普遍说又拍云和七牛比较好,看到七牛免费 ...
- 开源工作流 Bonita BPM (JAVA)
Bonita BPM 开源工作流 Bonita BPM (JAVA) http://www.bonitasoft.com/
- ZeroMQ(java)中对IO的封装(StreamEngine)
哎,各种各样杂七杂八的事情...好久没有看代码了,其实要搞明白一个与IO相关的框架,最好的办法就是把它的I/0的读写两个过程搞清楚...例如在netty中,如果能将eventLoop的运行原理搞清楚, ...
随机推荐
- 说下spring生命周期
面试官:说下spring生命周期 程序员:不会 那你先回去等消息吧 Bean实现了BeanNameAware,Spring会将Bean的ID透传给setBeanName java.后端开发.程 ...
- gentoo ebuild 私人portage
最近考虑搞个私人 portage, 用于一些软件的安装和管理. mkdir -p /usr/local/portage/app-misc/hello-world cd $_ cp /usr/porta ...
- python:win下将py文件打包成exe
[环境]windows,正常运行的python文件 1.安装pyinstaller ,cmd下执行以下命令,需看到安装成功界面 pip install pyinstaller 2.cmd中进入要打包的 ...
- orcal 安装失败解决办法
若安装失败
- Rhythmk 一步一步学 JAVA(6): JSP 语法学习笔记
1.修改JSP页面模版: 找到MyEclips安装目录,搜索“Jsp.vtl”,找到该文件修改编码,以及一些不需要用到的代码. 2.查找项目生成的Servlet文件路径: 查看当前项目父级目录搜索 . ...
- Innodb锁相关总结
一.InnoDB共有七种类型的锁: (1)共享/排它锁(Shared and Exclusive Locks) (2)意向锁(Intention Locks) (3)插入意向锁(Insert Inte ...
- python_09 文件处理流程,文件操作方法
文件处理流程 1.打开文件,得到文件句柄并赋值给一个变量 2.通过句柄对文件进行操作 3.关闭文件 f=open('test.txt',encoding='gbk') data = f.read() ...
- azkaban 执行hive语句
#hivef.jobtype=commandcommand=hive -f test.sql #test.sql use default;drop table aztest;create table ...
- springboot读取配置注解@ConfiguratioinProperties和@Value的区别
- 213. House Robber II 首尾相同的偷窃问题
[抄题]: You are a professional robber planning to rob houses along a street. Each house has a certain ...