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:
1. 两个指针 In-place
第一种是 in-place,具体实现过程如下:
1 | # Definition for singly-linked list. |
2. 两个指针
第二种是新构建两个链表分别存储,具体实现过程如下:
1 | class Solution: |