【LeetCode】Partition List
2015-03-04 10:34
411 查看
/** * 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) { ListNode *less = new ListNode(0); ListNode *more = new ListNode(0); ListNode *indexLess, *indexMore; less->next=NULL; indexLess = less; indexMore = more; if (head == NULL || head->next == NULL) return head; while (head) { if (head->val < x) { indexLess->next = head; head = head->next; indexLess = indexLess->next; indexLess->next = NULL; } else { indexMore->next = head; head = head->next; indexMore = indexMore->next; indexMore->next = NULL; } } indexLess->next = more->next; return less->next; } };
相关文章推荐
- LeetCode----Partition List
- leetcode---Partition List
- leetcode--Partition List
- (LeetCode 86)Partition List
- 【LeetCode】Partition List 解题报告
- leetcode: Partition List
- leetcode_86_Partition List
- 【leetcode】Partition List
- LeetCode---(86) Partition List
- 【LeetCode】Partition List
- LeetCode:Partition List
- [leetcode 86] Partition List
- 【leetcode】【单链表】【86】Partition List
- [Leetcode]#86 Partition List
- 【LeetCode练习题】Partition List
- LeetCode - Partition List
- [C语言][LeetCode][86]Partition List
- Leetcode:Partition List
- [LeetCode]Partition List
- leetcode-Partition List