[leetcode]Partition List
2013-07-20 15:36
369 查看
/** * 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 if(!head) return NULL; ListNode *lt = new ListNode(0); lt->next = head; ListNode *gt = new ListNode(0); ListNode *p = lt, *q = gt; while(p->next){ if(p->next->val >= x){ q->next = p->next; p->next = q->next->next; q = q->next; q->next = NULL; }else{ p = p->next; } } p->next = gt->next; head = lt->next; delete lt; delete gt; return head; } };
相关文章推荐
- LeetCode: Partition List
- [leetcode]Partition List
- leetcode - Partition List
- LeetCode() Partition List
- leetcode:Partition List
- LeetCode:Partition List
- LeetCode--Partition List
- leetcode -- Partition List -- 常见题型重点
- Leetcode: Partition List
- [LeetCode]Partition List
- LeetCode-Partition List
- LeetCode(87)Partition List
- LeetCode:Partition List
- 【LeetCode】Partition List 解题报告
- leetcode之Partition List
- [LeetCode] Partition List
- [leetcode-86]Partition List(c)
- LeetCode | Partition List(partition方法处理链表)
- [Leetcode]Partition List
- leetcode-- Partition List