Leetcode 86

/**
* 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) {
if(head == NULL) return head;
ListNode* pres = new ListNode(-);
pres->next = head;
ListNode* move = pres; ListNode* preb = new ListNode(-);
ListNode* move1 = preb;
while(move->next != NULL){
if(move->next->val < x){
move = move->next;
}
else if(move->next->val >= x){
move1->next = move->next;
move->next = move->next->next;
move1->next->next = NULL;
move1 = move1->next;
}
}
move->next = preb->next;
return pres->next;
}
};
上一篇:u Calculate e 分类: HDU 2015-06-19 22:18 14人阅读 评论(0) 收藏


下一篇:HDU 3635 并查集+路径压缩+记录每个点移动次数