题目
把一个链表平分两个部分
思路
双指针找中点
代码
def cut(lst):
head = lst.head
fast = head
slow = head
cut_node = slow
if head is None:
return 0
while fast is not None and fast.next is not None:
fast = fast.next.next
slow = slow.next
cut_node = slow
h2 = Linkedlist()
h2.head = Node()
h2.head.next = slow.next
cut_node.next = None
h1 = Linkedlist()
h1.head = head
return h1,h2