leetcode:Partition List
2015-04-01 16:07
239 查看
/** * 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 NULL; ListNode *low = new ListNode(-1), *low_tail = low; ListNode *high = new ListNode(-1), *high_tail = high; ListNode *cur = head; while(cur) { if(cur->val<x) { low_tail->next = cur; cur = cur->next; low_tail = low_tail->next; low_tail->next = NULL; } else { high_tail->next = cur; cur = cur->next; high_tail = high_tail->next; high_tail->next = NULL; } } low_tail->next = high->next; return low->next; } };
相关文章推荐
- leetcode 086 Partition List
- LeetCode - Partition List
- leetcode[86]Partition List
- LeetCode-Partition List-分割链表-链表操作
- Partition List 分类: Leetcode(链表) 2015-03-03 21:13 29人阅读 评论(0) 收藏
- leetcode-Partition List
- 【LeetCode】Partition List ——链表排序问题
- 【Leetcode 86】 Partition List
- leetcode_question_86 Partition List
- [LeetCode]86 Partition List
- 【leetcode】Partition List
- [Leetcode] Partition List
- leetcode-Partition List
- [LeetCode] Partition List 解题报告
- LeetCode - Refresh - Partition List
- LeetCode题解-86-Partition List
- [leetcode]Partition List
- leetcode--Partition List
- [Leetcode] Partition List
- leetcode:Partition List