看这趋势,abc没必要学中文# Parenting - 为人父母
j*r
1 楼
/**
* 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 dummy(0);
ListNode dummy2(0);
ListNode *p = &dummy;
ListNode *pp = &dummy2;
while(head) {
if (head->val < x) {
p->next = head;
p = p->next;
}
else {
pp->next = head;
pp = pp->next;
}
head = head->next;
}
p->next = dummy2.next;
return dummy.next;
}
};
* 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 dummy(0);
ListNode dummy2(0);
ListNode *p = &dummy;
ListNode *pp = &dummy2;
while(head) {
if (head->val < x) {
p->next = head;
p = p->next;
}
else {
pp->next = head;
pp = pp->next;
}
head = head->next;
}
p->next = dummy2.next;
return dummy.next;
}
};