题目:
题解:
class Solution:
def partition(self, head: Optional[ListNode], x: int) -> Optional[ListNode]:
sml_dummy, big_dummy = ListNode(0), ListNode(0)
sml, big = sml_dummy, big_dummy
while head:
if head.val < x:
sml.next = head
sml = sml.next
else:
big.next = head
big = big.next
head = head.next
sml.next = big_dummy.next
big.next = None
return sml_dummy.next