"""Definition of ListNodeclass ListNode(object): def __init__(self, val, next=None): self.val = val self.next = next"""classSolution:""" @param head: The first node of the linked list. @return: You should return the head of the reversed linked list. Reverse it in-place. """defreverse(self,head):# write your code hereifhead==Noneorhead.next==None:returnheadDummy_node=ListNode(-1,None)Dummy_node.next=headfront_node=Dummy_node.nextend_node=front_node.nextwhileend_node!=None:next_node=end_node.nextend_node.next=front_nodefront_node=end_nodeend_node=next_nodehead.next=Nonereturnfront_node