分隔链表
// 分隔链表
package linkedlist
// 力扣官方题解
func Partition(head *ListNode, x int) *ListNode {
small := &ListNode{}
smallHead := small
large := &ListNode{}
largeHead := large
for head != nil {
if head.Val < x {
small.Next = head
small = small.Next
} else {
large.Next = head
large = large.Next
}
head = head.Next
}
large.Next = nil
small.Next = largeHead.Next
return smallHead.Next
}