/**
* 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) {
ListNode *G = new ListNode(0);
ListNode *L = new ListNode(0);
ListNode *less = L;
ListNode *great = G;
while(head) {
if (head->val < x)
less = less->next = head;
else
great = great->next = head;
head = head->next;
}
great->next = NULL;
less->next = G->next;
return L->next;
}
};