class Node:
def __init__(self, x):
self.value = x
self.next = None
class LinkedListMid:
def __init__(self):
self.size = 0
self.head = Node(0)
def midOrUpMidNode(self, head):
if head is None or head.next is None or head.next.next is None:
return head
# 链表有三个点或以上
slow = head.next
fast = head.next.next
while fast.next is not None and fast.next.next is not None:
slow = slow.next
fast = fast.next.next
return slow
def midOrDownMidNode(self, head):
if head is None or head.next is None:
return head
slow = head.next
fast = head.next
while fast.next is not None and fast.next.next is not None:
slow = slow.next
fast = fast.next.next
return slow
def midOrUpMidPreNode(self, head):
if head is None or head.next is None or head.next.next is None:
return None
slow = head
fast = head.next.next
while fast.next is not None and fast.next.next is not None:
slow = slow.next
fast = fast.next.next
return slow
def midOrDownMidPreNode(self, head):
if head is None or head.next is None:
return None
if head.next.next is None:
return head
slow = head
fast = head.next
while fast.next is not None and fast.next.next is not None:
slow = slow.next
fast = fast.next.next
return slow