"""Definition of ListNodeclass ListNode(object): def __init__(self, val, next=None): self.val = val self.next = next"""classSolution:""" @param head: The first node of linked list. @param x: an integer @return: a ListNode """defpartition(self,head,x):# write your code hereifhead==Noneorhead.next==None:returnheaddummy=ListNode(0,None)left_list=dummydummy2=ListNode(0,None)right_list=dummy2whilehead!=None:ifhead.val<x:left_list.next=headleft_list=left_list.nextelse:right_list.next=headright_list=right_list.nexthead=head.next# connect left_list and right_listleft_list.next=dummy2.next# terminate the right listright_list.next=Nonereturndummy.next