Partition List
2013-08-22 05:28
239 查看
public ListNode partition(ListNode head, int x) { // Start typing your Java solution below // DO NOT write main() function if(head == null) return null; ListNode tmp = new ListNode(-1); tmp.next = head; ListNode current = head; ListNode previous = tmp; ListNode next = null; while(current.next != null && current.val < x) { previous = current; current = current.next; } while(current.next != null) { next = current.next; if(next.val < x) { current.next = next.next; next.next = previous.next; previous.next = next; previous = next; }else { current = current.next; } } head = tmp.next; tmp.next = null; return head; }
相关文章推荐
- [LeetCode] Partition List
- [leetcode]Partition List
- leetcode_question_86 Partition List
- Partition List
- Partition List
- [leetcode] Partition List
- Partition List
- Partition List
- LeetCode: Partition List
- leetcode 链表 Partition List
- Partition List
- Partition List
- Partition List
- [leetcode #86 链表] Partition List
- leetcode || 86、Partition List
- 2.2.3 Partition List
- Leetcode 86 Partition List
- 【LeetCode-面试算法经典-Java实现】【086-Partition List(将单链表进行分区)】
- [LeedCode OJ]#86 Partition List
- Leetcode138: Partition List