# [leetcode] 【链表】86. 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.

For example,
Given 1->4->3->2->5->2 and x = 3,

return 1->2->2->4->3->5.

# 题意

Given 1->4->3->2->5->2 and x = 3,

return 1->2->2->4->3->5.

# 题解

/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* partition(ListNode* head, int x) {
ListNode small(-1);
ListNode big(-1);
auto small_p=&small;
auto big_p=&big;
{
if(cur->val<x)
{
small_p->next=cur;
small_p=cur;
}
else
{
big_p->next=cur;
big_p=cur;
}
}
big_p->next=NULL;
small_p->next=big.next;
return small.next;
}
};

#### 【leetcode】【86】Partition List

2016-03-03 11:16:44

#### LeetCode 86（Partition List）java

2016-11-24 16:02:27

#### LeetCode 86 Partition List (Python详解及实现)

2017-08-09 17:15:43

#### [LeetCode] 86. Partition List 分隔链表 @python

2018-03-18 16:14:54

#### leetcode_86_Partition List

2015-02-05 21:57:59

#### 【LeetCode】Partition List 解题报告

2014-12-12 11:21:52

#### 【LeetCode-面试算法经典-Java实现】【086-Partition List（将单链表进行分区）】

2015-08-05 06:50:45

#### *Leetcode 86. Partition List

2017-06-11 00:54:10

#### leetcode: 86. Partition List

2017-11-21 10:11:51

#### Leetcode 86. Partition List

2016-04-06 13:38:53