Leetcode 86
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* partition(ListNode* head, int x) {
if(head == NULL) return head;
ListNode* pres = new ListNode(-);
pres->next = head;
ListNode* move = pres; ListNode* preb = new ListNode(-);
ListNode* move1 = preb;
while(move->next != NULL){
if(move->next->val < x){
move = move->next;
}
else if(move->next->val >= x){
move1->next = move->next;
move->next = move->next->next;
move1->next->next = NULL;
move1 = move1->next;
}
}
move->next = preb->next;
return pres->next;
}
};
Leetcode 86的更多相关文章
- 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 划分链表
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- Java实现 LeetCode 86 分割链表
86. 分隔链表 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的初始相对位置. 示例: 输入: head = 1 ...
- Leetcode 86. Unique Binary Search Trees
本题利用BST的特性来用DP求解.由于BST的性质,所以root左子树的node全部<root.而右子树的node全部>root. 左子树 = [1, j-1], root = j, 右子 ...
- 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] Scramble String
将一个单词按照这种方式分: Below is one possible representation of s1 = "great": great / \ gr eat / \ / ...
- 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 ...
随机推荐
- tomcat热启动没问题, 访问项目报500解决办法
新建maven项目 添加热启动 启动访问项目报错 报错提示 解决办法 思路:包冲突 在pom.xml中添加servlet <dependency> <groupId>javax ...
- js 变量提升(JavaScript Scoping and Hoisting)
原文网址:http://www.cnblogs.com/betarabbit/archive/2012/01/28/2330446.html 这是一篇作者翻译过来的文章,未翻译的原文网址在这里:htt ...
- Python3基础 help 查看内置函数说明
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 高通平台读写nv总结【转】
本文转载自:https://blog.csdn.net/suofeng12345/article/details/52713993 一,引言 1. 什么是NV 高通平台的NV,保 ...
- LightOJ - 1247 Matrix Game (Nim博弈)题解
题意: 给一个矩阵,每一次一个玩家可以从任意一行中选任意数量的格子并从中拿石头(但最后总数要大于等于1),问你谁赢 思路: 一开始以为只能一行拿一个... 将每一行石子数相加就转化为经典的Nim博弈 ...
- BZOJ5131: [CodePlus2017年12月]可做题2
BZOJ没有题面,差评 洛谷的题目链接 题解 其实这题很久之前就写了,也想写个题解但是太懒了,咕到了今天 在typora写完题解不想copy过来再改格式了,于是直接贴截图qwq #include &l ...
- 论文笔记——Data-free Parameter Pruning for Deep Neural Networks
论文地址:https://arxiv.org/abs/1507.06149 1. 主要思想 权值矩阵对应的两列i,j,如果差异很小或者说没有差异的话,就把j列与i列上(合并,也就是去掉j列),然后在下 ...
- [JVM] - 一份<自己动手写Java虚拟机>的测试版
go语言下载 配置GOROOT(一般是自动的),配置GOPATH(如果想自己改的话) 参照<自己动手写Java虚拟机> > 第一章 指令集和解释器 生成了ch01.exe文件 这里还 ...
- UVa 1343 旋转游戏(dfs+IDA*)
https://vjudge.net/problem/UVA-1343 题意:如图所示,一共有8个1,8个2和8个3,如何以最少的移动来使得中间8个格子都为同一个数. 思路:状态空间搜索问题. 用ID ...
- mvc ---- ajax 提交过来的Json格式如何处理(解析)
前台传过来的不是一个对象,而是一个Json字符串怎么办 ? 如: {","contents":"<p>lsdfjlsdjflsdf</p> ...