【Lintcode】096.Partition List
题目:
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
You should preserve the original relative order of the nodes in each of the two partitions.
Example
Given 1->4->3->2->5->2->null and x = 3,
return 1->2->2->4->3->5->null.
题解:
Solution 1 ()
class Solution {
public:
ListNode *partition(ListNode *head, int x) {
ListNode* left = new ListNode(-);
ListNode* right = new ListNode(-);
ListNode* l = left;
ListNode* r = right;
while (head) {
if (head->val < x) {
l->next = head;
l = l->next;
} else {
r->next = head;
r = r->next;
}
head = head->next;
}
l->next = right->next;
r->next = nullptr;
return left->next;
}
};
【Lintcode】096.Partition List的更多相关文章
- 【CF932G】Palindrome Partition(回文树,动态规划)
[CF932G]Palindrome Partition(回文树,动态规划) 题面 CF 翻译: 给定一个串,把串分为偶数段 假设分为了\(s1,s2,s3....sk\) 求,满足\(s_1=s_k ...
- 【CF932G】Palindrome Partition 回文自动机
[CF932G]Palindrome Partition 题意:给你一个字符串s,问你有多少种方式,可以将s分割成k个子串,设k个子串是$x_1x_2...x_k$,满足$x_1=x_k,x_2=x_ ...
- 【CF830C】Bamboo Partition 分块
[CF830C]Bamboo Partition 题解:给你n个数a1,a2...an和k,求最大的d使得$\sum\limits_{i=1}^n((d-a[i] \% d) \% d) \le k$ ...
- 【LeetCode】86. Partition List 解题报告(Python)
[LeetCode]86. Partition List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:// ...
- 【lintcode】 二分法总结 I
二分法:通过O(1)的时间,把规模为n的问题变为n/2.T(n) = T(n/2) + O(1) = O(logn). 基本操作:把长度为n的数组,分成前区间和后区间.设置start和end下标.i ...
- 【leetcode】698. Partition to K Equal Sum Subsets
题目如下: 解题思路:本题是[leetcode]473. Matchsticks to Square的姊妹篇,唯一的区别是[leetcode]473. Matchsticks to Square指定了 ...
- 【原创】leetCodeOj ---Partition List 解题报告
原题地址: https://oj.leetcode.com/problems/partition-list/ 题目内容: Given a linked list and a value x, part ...
- 【Leetcode】86. Partition List
Question: Given a linked list and a value x, partition it such that all nodes less than x come befor ...
- 【Lintcode】136.Palindrome Partitioning
题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...
随机推荐
- 还需要学习的十二种CSS选择器
在前面的文章中,我们在介绍了<五种你必须彻底了解的CSS选择器>,现在向大家介绍,还需要学习的另外十二种CSS选择器.如果你还没有用过,就好好学习一下,如果你已经熟知了就当是温习. 一.X ...
- 用GetTickCount()计算一段代码执行耗费的时间的小例子
var aNow,aThen,aTime:Longint; begin aThen := GetTickCount(); Sleep();//代码段 aNow := GetTickCount(); a ...
- delphi 解析Json格式(转自:http://blog.csdn.net/jayqiang/article/details/7066824)
SuperObject 是开源的 Delphi 的 JSON 工具包,可生成 JSON 数据以及进行 JSON 解析. unit Unit6; interface uses Windows, Mess ...
- libEasyPlayer RTSP windows播放器SDK API接口设计说明
概述 libEasyPlayer实现对RTSP直播流进行实时采集和解码显示,稳定,高效,低延时:解码可采用intel硬件解码和软件解码两种方式,能实时进行录像和快照抓图,OSD叠加等功能. API接口 ...
- MySQL——事务
核心知识: 1.什么是事务?一组原子性的SQL查询语句 2.事务的四种属性:ACID 3.四种隔离级别:读取未提交内容.读取提交内容.重复读.串行化. 4.什么是幻读?幻读有那些解决办法?连续读取同一 ...
- could not read symbols: Archive has no index;
could not read symbols: Archive has no index; run ranlib to add one collect2: ld returned 1 exit sta ...
- java: new Date().getTime() 与 System.currentTimeMillis() 与 System.nanoTime()
java使用new Date()和System.currentTimeMillis()获取当前时间戳 在开发过程中,通常很多人都习惯使用new Date()来获取当前时间,使用起来也比较方便,同时 ...
- HDU 2138 How many prime numbers(Miller_Rabin法判断素数 【*模板】 用到了快速幂算法 )
How many prime numbers Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- Spring Boot2.0之自定义参数
自定义参数,把不同环境的配置放到配置文件中去. 不同环境,如何区分配置文件信息,自定义配置文件信息 比如在 application.properties定义个参数 name=toov5 Spring ...
- Linux学习之路(三)搜索命令
1.文件搜索命令locate 2.命令搜索命令whereis与which 3.字符串搜索命令grep 4.find命令与grep命令的区别 locate命令相对于find命令搜索非常快,find命令在 ...