本文共 1060 字,大约阅读时间需要 3 分钟。
class Solution {public: ListNode* partition(ListNode* head, int x) { if(!head||!head->next) return head; ListNode *less=NULL; ListNode *more=NULL; ListNode *morehead=NULL; ListNode *lesshead=NULL; while(head) { if(head->valnext; } else { less->next=head; less=less->next; head=head->next; } } else { if(!more) { more=head; morehead=head; head=head->next; } else { more->next=head; more=more->next; head=head->next; } } } if(!morehead) return lesshead; else if(!lesshead) return morehead; more->next=NULL; less->next=morehead; return lesshead; }};
转载地址:http://nhked.baihongyu.com/