新建两个list,然后遍历原来的list,不断的填充
func partition(head *ListNode, x int) *ListNode {
beforehead := &ListNode{}
before := beforehead
afterhead := &ListNode{}
after := afterhead
for head != nil {
if head.Val < x {
before.Next = head
before = before.Next
} else {
after.Next = head
after = after.Next
}
head = head.Next
}
after.Next = nil
before.Next = afterhead.Next
return beforehead.Next
}