【leetcode】Partition List(middle)
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.
For example,
Given 1->4->3->2->5->2
and x = 3,
return 1->2->2->4->3->5
.
思路:先分成大于等于x 和 小于x 两个链表 再连起来 还是用伪头部
class Solution {
public:
ListNode *partition(ListNode *head, int x) {
ListNode large(), small();
ListNode * l = &large;
ListNode * s = &small; while(head != NULL)
{
if(head->val < x)
{
s = s->next = head;
}
else
{
l = l->next = head;
}
head = head->next;
} l->next = NULL;
s->next = large.next;
return small.next;
}
};
【leetcode】Partition List(middle)的更多相关文章
- 【leetcode】Reverse Integer(middle)☆
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 总结:处理整数溢出 ...
- 【leetcode】Reorder List (middle)
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...
- 【leetcode】Word Break (middle)
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- 【leetcode】Rotate List(middle)
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- 【leetcode】Spiral Matrix(middle)
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- 【leetcode】Rotate Image(middle)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- 【leetcode】Next Permutation(middle)
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- 【leetcode】Reverse Bits(middle)
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【leetcode】Surrounded Regions(middle)☆
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...
随机推荐
- WCF自定义扩展,以实现aop!
引用地址:https://msdn.microsoft.com/zh-cn/magazine/cc163302.aspx 使用自定义行为扩展 WCF Aaron Skonnard 代码下载位置: S ...
- 基于iSCSI的SQL Server 2012群集测试(二)--SQL群集安装后初始化配置测试
4.群集安装后初始化配置测试 4.1 禁用full-text 服务和Browser服务 Full-text服务:公司目前暂不使用,需在两个节点上分别禁用 Browser服务:为保证安全,建议将Brow ...
- MMTx使用说明
MMTx(MetaMap Transfer)是美国国家医学图书馆建立的用于文本数据挖掘的一种工具. 下面以Medine格式数据为例介绍使用方法 1.在PubMed数据库检索相关的文献. 2.将数据结果 ...
- java常量池存放在哪里
运行以下方法: public class Test { public static void main(String[] args) { String str = "abc"; c ...
- mac os 基本命令
unix 系统命令行 ,仅供参考 目录操作 命令名 功能描述 使用举例 mkdir 创建一个目录 mkdir dirname rmdir 删除一个目录 rmdir dirname ...
- PHPCMS系统使用的弹出窗口插件artDialog
来源: http://aui.github.io/artDialog/doc/index.html (官方) http://lab.seaning.com/ http://www.mb5u.com/ ...
- OSGi——面向服务架构规范简述
OSGi——面向服务架构规范简述 去年我们组要开发一个新的产品,在讨论产品架构路线的时候,美国的架构师向大家征集了架构设计思想(我推荐了SCSF),有一位工程师向他推荐了OSGi.以前我还没有听过OS ...
- Oracle Redo
Redo log 重做日志在Oracle数据库中,有一种日志文件叫做重做日志文件,他就是大家俗称的:redolog.在redolog中又分为两种:在线重做日志与归档日志. ONLINE Redo lo ...
- 一颗躁动的心---下决心从SLAM开始,不钻研嵌入式底层了
在写这个随笔时,北京的外面正在下2016的第一场雪.夜深人尽之时总会考虑一下自己的未来在何方. 长这么大了,我发现我这人始终不能坚定不移的朝着一个方向努力,总是朝三暮四,对学习更是朝令夕改,这造成了我 ...
- Tomcat 7最大并发连接数的正确修改方法
这是个很简单的问题,但是搜了一圈,发现大家都写错了.所以这里总结一下: 几乎所有的中文网页都介绍,要修改Tomcat的默认最大并发连接数,应该进行如下设置(实际上这些步骤是错误的): -------- ...