实现求链表的中间结点
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
import math
class Solution:
def middleNode(self, head):
# 首先要知道链表一共有多少个结点
count = 0
res = {}
while head != None:
count += 1
res[count] = head
head = head.next
#j = math.ceil(count/2)
#if count % 2 == 0:
# return res[j+1]
#else:
# return res[j]
j = math.ceil((count-1)/2) + 1
return res[j]