86. Partition List
problem descripiton
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:
algorithm thought
首先初始化两个头,然后将两个partition,分别加到两个头上,最后将两个partition合并
code
algorithm analysis
算法一次遍历链表,时间复杂度O(n)
Last updated