/*
这个题是medium的意思应该是用双指针的方法做,如果使用下边的新建链表的方法,就是easy的题目了
双指针会用到很多链表的相连操作
*/
public ListNode partition(ListNode head, int x) {
ListNode s = null;
ListNode b = null;
ListNode temp=null,res=null;
while (head!=null)
{
int cur = head.val;
if (head.val<x)
{
if (s==null) {
s = new ListNode(cur);
res = s;
}
else {
s.next = new ListNode(cur);
s = s.next;
}
}
else
{
if (b==null) {
b = new ListNode(cur);
temp = b;
}
else {
b.next = new ListNode(cur);
b = b.next;
}
}
head = head.next;
}
if (s==null) return temp;
s.next = temp;
return res;
}

[LeetCode]86. Partition List分离链表的更多相关文章

  1. [LeetCode] 86. Partition List 划分链表

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  2. LeetCode 86. Partition List 划分链表 C++

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  3. [leetcode]86. Partition List划分链表

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  4. leetCode 86.Partition List(分区链表) 解题思路和方法

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  5. leetcode 86. Partition List

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  6. [LeetCode] 86. Partition List 解题思路

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  7. LeetCode 86. 分隔链表(Partition List)

    86. 分隔链表 86. Partition List 题目描述 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的 ...

  8. LeetCode 86 | 链表基础,一次遍历处理链表中所有符合条件的元素

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题第53篇文章,我们一起来看LeetCode第86题,Partition List(链表归并). 本题的官方难度是M ...

  9. 【LeetCode】86. Partition List 解题报告(Python)

    [LeetCode]86. Partition List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:// ...

随机推荐

  1. 这次我让你彻底弄懂 RESTful

    微信搜 「yes的练级攻略」干货满满,不然来掐我,回复[123]一份20W字的算法刷题笔记等你来领.欢迎分享,转载请保留出处. 本文已收录至 https://github.com/yessimida/ ...

  2. Django 在test.py 中测试文件的配置

    import os import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTING ...

  3. fist-第七天冲刺随笔

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE1 这个作业要求在哪里 https://edu.cnblogs.com/campus/fz ...

  4. moviepy音视频剪辑:与大小相关的视频变换函数详解

    ☞ ░ 前往老猿Python博文目录 ░ 一.引言 在<moviepy音视频剪辑:moviepy中的剪辑基类Clip详解>介绍了剪辑基类的fl.fl_time.fx方法,在<movi ...

  5. Python中函数是否能使用全局变量?

    Python函数中的变量,既可以使用局部变量(本地名字空间的变量),也可以使用全局变量(全局名字空间的变量),函数在执行查找变量只读时,先在局部变量中查找,找不到再查到全局变量中查找.因此当局部变量和 ...

  6. 利用Python特殊变量__dict__快速实现__repr__的一种方法

    在<第8.15节 Python重写自定义类的__repr__方法>.<Python中repr(变量)和str(变量)的返回值有什么区别和联系>.<第8.13节 Pytho ...

  7. 第15.33节 PyQt(Python+Qt)入门学习:containers容器类部件QTabWidget选项窗部件简介

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.概述 容器部件就是可以在部件内放置其他部件的部件,在Qt Designer中可以使用的容器部件有 ...

  8. PyQt(Python+Qt)学习随笔:QTreeView树形视图的itemsExpandable属性

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTreeView树形视图的itemsExpandable属性用于控制视图中用户是否可以通过操作展开 ...

  9. APP软件系统测试

    1.功能模块测试 2.交叉事件测试 3.压力测试 存储压力测试 边界压力测试 响应能力压力测试 网络流量测试 4.容量测试 5.安装卸载测试 6.易用性.用户体验测试 7.UI界面测试

  10. Hangfire&Autofac与ASP.NET CORE注入失败

    Hangfire.Autofac与ASP.NET CORE注入失败 项目里面使用了Hangfire,因为之前没用过吧,遇到了个问题,就是使用了ico容器后,再用Hangfire总是注入不上对象,总是后 ...