class Solution:
def partition(self, head: ListNode, x: int) -> ListNode:
small, large = ListNode(0), ListNode(0)
s, l, i = small, large, head
while i:
if i.val < x:
s.next = i
s = s.next
else:
l.next = i
l = l.next
i = i.next
s.next = large.next #small链接上large链
l.next = None #large链末尾置空
return small.next