[LeetCode]86. Partition List分离链表
/*
这个题是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分离链表的更多相关文章
- [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 ...
- 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 ...
- [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 ...
- 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 ...
- 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 ...
- [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 ...
- LeetCode 86. 分隔链表(Partition List)
86. 分隔链表 86. Partition List 题目描述 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的 ...
- LeetCode 86 | 链表基础,一次遍历处理链表中所有符合条件的元素
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题第53篇文章,我们一起来看LeetCode第86题,Partition List(链表归并). 本题的官方难度是M ...
- 【LeetCode】86. Partition List 解题报告(Python)
[LeetCode]86. Partition List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:// ...
随机推荐
- java中的强引用(Strong reference),软引用(SoftReference),弱引用(WeakReference),虚引用(PhantomReference)
之前在看深入理解Java虚拟机一书中第一次接触相关名词,但是并不理解,只知道Object obj = new Object()类似这种操作的时候,obj就是强引用.强引用不会被gc回收直到gc roo ...
- 「考试」联赛模拟36-39,noip晚间小测2-3
36.1 party(CF623D) 很是鸡贼的一道题 首先要明确一点,抓人是有策略,而不是随机的,可以认为等同于按一个给定的顺序猜人,那么这时猜中的概率就只是抓住这个人的概率了 对于每一次猜测,因为 ...
- 【2020.12.03提高组模拟】A组反思
估计:40+10+0+0=50 实际:40+10+0+0=50 rank40 T1 赛时看到\(n,m\leq9\),我当机立断决定打表,暴力打了几个点之后发现在\(n\ne m\)且\(k\ne0\ ...
- 浅尝 Elastic Stack (二) Logstash
一.安装与启动 Logstash 依赖 Java 8 或者 Java 11,需要先安装 JDK 1.1 下载 curl -L -O https://artifacts.elastic.co/downl ...
- 树莓派自动连接WiFi
使用sudo raspi-config配置好第一个wifi 然后只需要修改一个文件sudo nano /etc/wpa_supplicant/wpa_supplicant.conf 内容如下: ctr ...
- go语言的指针类型
一.指针与引用的相关概念 什么是指针? 指针,全称为指针变量,是用来存储内存地址的一种变量.程序中,一般通过指针来访问其指向的内存地址中的内容(数据). 什么是引用? 引用,是C++中提出来的一种新的 ...
- 第三十四章、PyQt中的输入部件:QComboBox组合框功能详解
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 一.概述 Designer中输入工具部件中的Combo Box组合框与 ...
- PyQt(Python+Qt)学习随笔:Qt Designer中部件的geometry几何属性
geometry属性保存部件相对于其父级对象的位置和大小,Qt实际上是以一个长方形来表示部件的位置和大小的,包括左上角的坐标位置.长度和宽带. 当部件的geometry调整时,部件如果可见将立即接收m ...
- 手写mini版MVC框架
目录 1, Springmvc基本原理流程 2,注解开发 编写测试代码: 目录结构: 3,编写自定义DispatcherServlet中的初始化流程: 3.1 加载配置文件 3.2 扫描相关的类,扫描 ...
- ollvm在VS2017下编译
0x1,首先介绍一下编译环境配置 1.UE4.25 2.vs2017(15.9),注:2019编译总是出现错误 3.cmake3.18.5,cmake的作用是为ollvm源码编译成适合于在vs2017 ...