[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:// ...
随机推荐
- LeetCode 034 Search for a Range
题目要求:Search for a Range Given a sorted array of integers, find the starting and ending position of a ...
- java顺序、选择、循环结构
一.顺序结构 二.选择结构 1.if都执行 2.if else if else 条件满足才执行 3.选择结构switch 一个case后有多条语句要加花括号 多个case的值不能相同 case中要加b ...
- Django 多对多表的三种创建方式
第一种: class Book(models.Model): name = models.CharField(max_length=32) # 第一种自动创建 authors = models.Man ...
- .Net编码规范整理
前言 此处只是整理并记录下.Net开发规范以便加深编码规范.一个好的编程规范可以让自己程序可读性,让自己编码更规范,分为两部分:通用规范..Net开发规范. 微软通用编程规范 明确性和一致性 库的使用 ...
- 老猿学5G扫盲贴:NEF、NRF、AF、UPF以及DN的功能
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 NEF:Network Exposure Function ,网络开放 ...
- 用Python爬取了三大相亲软件评论区,结果...
小三:怎么了小二?一副愁眉苦脸的样子. 小二:唉!这不是快过年了吗,家里又催相亲了 ... 小三:现在不是流行网恋吗,你可以试试相亲软件呀. 小二:这玩意靠谱吗? 小三:我也没用过,你自己看看软件评论 ...
- HTTP慢速拒绝服务攻击(Slow HTTP Dos)
HTTP慢速拒绝服务攻击简介 HTTP慢速攻击是利用HTTP合法机制,以极低的速度往服务器发送HTTP请求,尽量长时间保持连接,不释放,若是达到了Web Server对于并发连接数的上限,同时恶意占用 ...
- 【面试题】GC Root都有哪些?
那天去面试,面试官问我JVM垃圾回收,我是有备而来,上来就是一个可达性分析算法,然后就是一个复制算法,标记-清理,标记-整理,以及几个常见的垃圾回收器 详情见:https://www.cnblogs. ...
- 2、tensorflow 变量的初始化
https://blog.csdn.net/mzpmzk/article/details/78636137 关于张量tensor的介绍 import tensorflow as tf import n ...
- OI知识点/得分技巧的归纳总结
网络流 拆点/拆边技巧 题目来源 bzoj1070 题目描述 同一时刻有\(N\)位车主带着他们的爱车来到了汽车维修中心.维修中心共有\(M\)位技术人员,不同的技术人员对不同 的车进行维修所用的时间 ...