/**
* 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的更多相关文章

  1. LeetCode 86. 分隔链表(Partition List)

    86. 分隔链表 86. Partition List 题目描述 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的 ...

  2. LeetCode 86 | 链表基础,一次遍历处理链表中所有符合条件的元素

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题第53篇文章,我们一起来看LeetCode第86题,Partition List(链表归并). 本题的官方难度是M ...

  3. [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 ...

  4. Java实现 LeetCode 86 分割链表

    86. 分隔链表 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的初始相对位置. 示例: 输入: head = 1 ...

  5. Leetcode 86. Unique Binary Search Trees

    本题利用BST的特性来用DP求解.由于BST的性质,所以root左子树的node全部<root.而右子树的node全部>root. 左子树 = [1, j-1], root = j, 右子 ...

  6. 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 ...

  7. [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 ...

  8. leetcode[86] Scramble String

    将一个单词按照这种方式分: Below is one possible representation of s1 = "great": great / \ gr eat / \ / ...

  9. 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 ...

  10. [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 ...

随机推荐

  1. oracle_存储过程小记

    # 刷新会员标签函数 {color:red} fun_refresh_code{color} {noformat}CREATE OR REPLACE FUNCTION fun_refresh_code ...

  2. java和mysql之间的时间日期类型传递

    摘自:http://blog.csdn.net/weinianjie1/article/details/6310770 MySQL(版本:5.1.50)的时间日期类型如下: datetime 8byt ...

  3. 文本框获取光标位置 ---- ctrl+enter换行

    业务需求:按下enter键发送信息,按下ctrl+enter键换行 下面代码是网上找的资料 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 T ...

  4. MySQL Crash Course #12# Chapter 18. Full-Text Searching

    INDEX 由于性能.智能结果等多方面原因,在搜索文本时,全文搜索一般要优于通配符和正则表达式,前者为指定列建立索引,以便快速找到对应行,并且将结果集智能排序.启用查询扩展可以让我们得到未必包含关键字 ...

  5. c++学习之map基本操作

    map作为最常用的数据结构之一,用的好可以大幅度的提升性能. // java_cpp_perftest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h& ...

  6. 从Oracle到MySQL,余额宝云实践分享

    原文链接:http://www.csdn.net/article/2013-11-/2817426-interview-financial-case-yuerbao-aliyun07 余额宝.百度百发 ...

  7. Java 问卷调查

    对于我的未来,我打算现在学校好好学习专业知识,打下牢固的知识基础,为以后在工作岗位上能够顺利完成任务而努力. 在我看来,学习是一个接触并了解新事物的过程,掌握和应用这些新知识就是学习的目的.然而我们学 ...

  8. 《网络攻防》实验九:web安全基础实践

    本次实验在XX同学的指导下完成 1.实验后回答问题 (1)SQL注入攻击原理,如何防御 SQL注入攻击的基本原理,是从客户端合法接口提交特殊的非法代码,让其注入到服务器端执行业务的SQL中去,进而改变 ...

  9. 20145332 MAL_简单后门

    20145332 MAL_简单后门 用NC获取远程主机的shell 2.1.1 Windows获得Linux的权限 首先要在Windows主机下安装ncat.exe,安装完成后需要配置环境变量path ...

  10. RNN网络【转】

    本文转载自:https://zhuanlan.zhihu.com/p/29212896 简单的Char RNN生成文本 Sherlock I want to create some new thing ...