/**
* 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. 在Linux 中进入单用户模式的技巧

    在这篇简短的文章中,我们将向你介绍在 SUSE 12 Linux 中进入单用户模式的步骤.在排除系统主要问题时,单用户模式始终是首选.单用户模式禁用网络并且没有其他用户登录,你可以排除许多多用户系统的 ...

  2. Java MD5校验与RSA加密

    区别: MD5加密: 加密时通过原字符串加密成另一串字符串 解密时需要原加密字符串进行重新加密比较两次加密结果是否一致 RSA加密: 加密时通过原字符串生成密钥对(公钥+私钥) 解密时通过公钥和私钥进 ...

  3. SQL锁机制和事务隔离级别

    摘自:http://www.cnblogs.com/haiyang1985/archive/2009/02/27/1399641.html 锁机制 NOLOCK和READPAST的区别. 1.     ...

  4. Eclipse编码规范——Code Templates设置

    Eclipse编码规范——Code Templates设置 Eclipse编码规范主要包括三个方面:设置Code Templates.Eclipse formatter.Checkstyle, 本篇主 ...

  5. js常量

    原文链接:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/const const 声明创建一个 ...

  6. CodeForces 471D MUH and Cube Walls -KMP

    Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of ...

  7. 获取GetOpenFileName多选文件名

    void CWriteWnd::OpenFileDialog() { OPENFILENAME ofn; TCHAR szOpenFileNames[*MAX_PATH] = _T("&qu ...

  8. AS语法

    SELECT COUNT(*) AS NumberOfOrders FROM Orders 含义:将选出的数据作为一列显示,列名为NumberOfOrders

  9. windows下如何解决chrome浏览器左下角总提示'Downloading proxy script'的问题

    答:关掉LAN settings中的Automatically detect settings选项和Use automatic configuration script选项,如下图

  10. JavaScript 题目

    1. ],b=a; b[]=; console.log(a+b); a=[], b=a, b=[]; console.log(a+b); 2.快速排序法 var quickSort = functio ...