/**
* 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) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
ListNode* pLess = NULL;
ListNode** ppLess = &pLess;
ListNode* pGreater = NULL;
ListNode** ppGreater = &pGreater;
ListNode* cur = head;
while (cur)
{
if (cur->val < x)
{
*ppLess = cur;
ppLess = &(cur->next);
}
else
{
*ppGreater = cur;
ppGreater = &(cur->next);
}
cur = cur->next;
}
*ppLess = NULL;
*ppGreater = NULL;
if (pLess)
{
*ppLess = pGreater;
return pLess;
}
else
return pGreater;
return pLess;
}
};[Leetcode] Partition List
最新推荐文章于 2019-07-16 09:33:43 发布
415

被折叠的 条评论
为什么被折叠?



