LeetCode in Java [10]: 86. Partition List
Given a linked list and a value x , partition it such that all nodes less than x come before nodes greater than or equal to x . You should preserve the original relative order of the nodes in each of the two partitions. Example: Input: head = 1->4->3->2->5->2, x = 3 Output: 1->2->2->4->3->5 自己的想法链表元素的移动法要处理的细节比如两指针预先就位什么的很多很麻烦,结果: Success Runtime: 0 ms, faster than 100.00% of Java online submissions for Partition List. Memory Usage: 36 MB, less than 100.00% of Java online submissions forPartition List. 代码: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode