題目地址
兩個(gè)注意點(diǎn)
1叁执、dummy node
2娶眷、more.next = None 記得較大的鏈表的next值為none,有可能成為循環(huán)鏈表
def partition(self, head, x):
# write your code here
if head == None or head.next == None:
return head
head_little = ListNode(0)
head_more = ListNode(0)
little = head_little
more = head_more
while head:
if head.val < x:
little.next = head
little = head
else:
more.next = head
more = head
head = head.next
more.next = None
little.next = head_more.next
return head_little.next