果然审稿 是最厚的。。。# Immigration - 落地生根
m*p
1 楼
为什么泥?
class Solution {
public:
ListNode *partition(ListNode *head, int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
ListNode* dummy = new ListNode(-1);
ListNode* pivot = new ListNode(x);
ListNode* dummy_tail = dummy;
ListNode* pivot_tail = pivot;
ListNode* cur = head;
while (cur) {
if (cur->val < x) {
dummy_tail->next = cur;
dummy_tail = dummy_tail->next;
} else {
pivot_tail->next = cur;
pivot_tail = pivot_tail->next;
}
cur = cur->next;
}
dummy_tail->next = pivot->next;
ListNode* new_head = dummy->next;
delete dummy;
delete pivot;
return new_head;
}
};
class Solution {
public:
ListNode *partition(ListNode *head, int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
ListNode* dummy = new ListNode(-1);
ListNode* pivot = new ListNode(x);
ListNode* dummy_tail = dummy;
ListNode* pivot_tail = pivot;
ListNode* cur = head;
while (cur) {
if (cur->val < x) {
dummy_tail->next = cur;
dummy_tail = dummy_tail->next;
} else {
pivot_tail->next = cur;
pivot_tail = pivot_tail->next;
}
cur = cur->next;
}
dummy_tail->next = pivot->next;
ListNode* new_head = dummy->next;
delete dummy;
delete pivot;
return new_head;
}
};